• Resolved zetland

    (@zetland)


    Hey Frank,

    Thanks for this great plug-in. I just have a question about jQuery though. I’m only using it in any major way on my homepage, which features a slider. The others don’t need it, however jQuery is still acting as render-blocking JavaScript and giving me a poor PageSpeed score.

    Is there any configuration which allows me to optimize jQuery on every page except my homepage?

    Thanks,

    James

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Frank Goossens

    (@futtta)

    good question @zetland ??

    this can be accomplished by removing js/jquery/jquery.js from the list of AO JS optimization exclusions and a couple of lines of code against AO’s API actually, something like this (warning; untested code);

    add_filter('autoptimize_filter_js_exclude','exclude_jq_hp',10,1);
    function exclude_jq_hp($in) {
        if ( is_front_page() ) {
            return $in.",js/jquery/jquery.js";
        } else {
            return $in;
        }
    }
    

    hope this helps,
    frank

    Thread Starter zetland

    (@zetland)

    Thanks Frank, which plugin file should I add this to though?

    James

    Plugin Author Frank Goossens

    (@futtta)

    not to a plugin file (in general those shouldn’t be touched). the safest/ easiest way to add the code is by installing the code snippets plugin.

    Thread Starter zetland

    (@zetland)

    Is the is_front_page() function undefined? I’ve added the exact code as it is, but it doesn’t seem to be blocking jQuery from any page.

    Plugin Author Frank Goossens

    (@futtta)

    well, the code was step 2, but did you also try step 1;

    removing js/jquery/jquery.js from the list of AO JS optimization exclusions

    Thread Starter zetland

    (@zetland)

    Ah hell, sorry about that. Working very nicely now.

    Plugin Author Frank Goossens

    (@futtta)

    happy it works! ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Optimise jQuery on some specific pages’ is closed to new replies.