Support » Plugin: Autoptimize » Defer Inline JS for specific post type

  • Resolved woorooo

    (@woorooo)


    Hi Frank,

    Is there a way to use the new “defer inline js” option, but only for blog posts (not pages, or custom post types)?

    I need jquery.js and jquery.min.js loaded normally everywhere except blog posts. Blog posts on the other hand could use some performance boost and this is where the new “defer inline” option does wonders for my website.

    Thanks,

    Roman.

    • This topic was modified 2 months, 3 weeks ago by woorooo.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    with some code; sure, disable “defer inline” and use a code snippet to enable it for blogposts (is_single) with the autoptimize_js_filter_defer_inline filter? 🙂

    Thread Starter woorooo

    (@woorooo)

    Thank you 🙂

    By the way is there a website where I could find all the filters I could use with Autoptimize? I tried google, but couldn’t find it.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    github search could be a starting place? 😉

    Thread Starter woorooo

    (@woorooo)

    Sorry, I’m not a professional web developer, more like a hobbyist and not very familiar with github, but I’m doing my best and learning new things, thank you 🙂

    I was wondering if I can have AO aggregate js files with a certain list of exclusions by default, but at the same time disable aggregation and use defer js option with a shorter exclusion list for blog posts? For that I’ve tried using this code:

    add_filter('autoptimize_filter_js_exclude','my_ao_exclusion_list');
    function my_ao_exclusion_list($in) {
        if ( !is_singular(array( 'post' )) ) {
            return $in.'lazyload.min.js, js/jquery/jquery.min.js, js/jquery/jquery.js';
    	} else {
            return $in.'lazyload.min.js';
        }
    }
    
    add_filter('autoptimize_filter_js_dontaggregate','my_ao_dontaggregate');
    function my_ao_dontaggregate() {
        if ( is_singular(array( 'post' )) ) {
            return true;
    	} else {
            return false;
        }
    }
    
    add_filter('autoptimize_filter_js_defer_not_aggregate','my_ao_defer_not_aggregate');
    function my_ao_defer_not_aggregate () {
        if ( is_singular(array( 'post' )) ) {
            return true;
    	} else {
            return false;
        }
    }
    
    add_filter('autoptimize_js_filter_defer_inline','my_ao_defer_inline');
    function my_ao_defer_inline () {
        if ( is_singular(array( 'post' )) ) {
            return true;
    	} else {
            return false;
        }
    }
    
    

    It did the trick for blog posts, however other pages do not aggregate js files.

    Do you have any suggestions on what am I doing wrong here and if is it even possible what I’m attempting to do?

    Thanks.

    • This reply was modified 2 months, 3 weeks ago by woorooo.
    • This reply was modified 2 months, 3 weeks ago by woorooo.
    • This reply was modified 2 months, 3 weeks ago by woorooo.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Does anything change when you change

    } else {
            return;

    into

    } else {
            return false;
    Thread Starter woorooo

    (@woorooo)

    Thank you, I’ve found an error when naming the function with the exclusion list, I’ve also updated it up there and it seems to work as expected. Thank you so much 🙂

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    great job, enjoy the rush of seeing your code work Roman! 🙂

    And feel free to leave a review of the plugin and support here! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.