Home Forums Product Support Zealot What is the best way to eliminate render-blocking JavaScript and CSS in Zealot?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #14993
    Sally Cole
    Participant

    Hello,

    Can you recommend a WordPress plugin or other way to follow the Google PageSpeed Insights advice to “Eliminate render-blocking JavaScript and CSS in above-the-fold content”?

    I’m hoping there is an easy way to do this that is compatible with the Zealot theme.

    Thanks!
    Sally

    #14998
    Hyun Supul
    Keymaster

    Hi Sally,
    I am not the best person to answer this. But I don’t see why Zealot wouldn’t be compatible with anything else.

    However if you find some specific incompatibility, or you see some specific thing inside Zealot or Aesop that reported to be an issue by the Inights or other plugin, let me know.

    Hyun

    #15078
    Sally Cole
    Participant

    Hi Hyun,

    Thanks for the answer. Doing a little more investigation, I found that the pages where I have a lot of embedded YouTube videos load slowly. A test on gtmetrix.com says that I should defer parsing of Javascript.

    You can see the results of the test here:
    https://gtmetrix.com/reports/storyhouracademy.com/VqJDivXJ

    The best article I can find about deferring parsing of Javascript is here: https://mygenesisthemes.com/defer-parsing-of-javascript-wordpress/

    It says, “The possible solution is loading main content first then JavaScript files.The following code will ensure that all external JavaScript files will be loaded only after the main document is loaded. After adding this code in your child theme’s functions.php file, check the website speed in Google Speed Insights, Pingdom and GtMetrix tools.I hope the problem was solved.”

    This is the code they provide:

    function defer_parsing_of_js ( $url ) {
    if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
    if ( strpos( $url, ‘jquery.js’ ) ) return $url;
    return “$url’ defer “;
    }
    add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );

    I tried to add this to the Zealot functions.php file myself using WPide. However, WPide wouldn’t save it and so I couldn’t test it.

    Do you think this solution could work? If so, how do I get this code in the functions.php file?

    Thank you!
    Sally

    #15086
    Sally Cole
    Participant

    I ended up using CloudFlare and W3 Total Cache. Seems to be working great.

    I started with CloudFlare via this video:

    Then, I added W3 Total Cache with this article:
    http://www.bloggingwizard.com/w3-total-cache-cloudflare/

    #15097
    Hyun Supul
    Keymaster

    Hi Sally, glad that things are working out for you. As for why you can’t save the code in WPIDE, I believe that’s because the quotes are not actually the right characters. If you copy and paste the following it may work. Or simply retype each single and double quotes by hand.

    
    function defer_parsing_of_js ( $url ) {
    	if ( FALSE === strpos( $url, '.js' ) ) return $url;
    	if ( strpos( $url, 'jquery.js' ) ) return $url;
    	return "$url' defer ";
    }
    add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
    #15227
    Sally Cole
    Participant

    Hi Hyun,

    Thanks for catching the problem with the quotes. That gets me one step closer. Now, WPide shows the following error:

    Syntax error, unexpected T_STRING, expecting T_FUNCTION

    Any ideas how to resolve that error?

    Thank you!
    Sally

    #15228
    Hyun Supul
    Keymaster

    Hi can you send me login information to your website again using private reply? (You can email me directly at hyunsupul at gmail if you want) I will take a look at it and fix the code for you.

    Hyun

    #15231
    Hyun Supul
    Keymaster

    Hi Sally, I added the code using “Code Snippets” plugin. This would be a better way than editing functions.php directly anyway.

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