Defer Parsing of JavaScript in WordPress

0

Hello everyone,  Now in this post we are going to add a small code to your functions.php file of your WordPress theme to Defer Parsing of JavaScript in WordPress and hence to speed up your WordPress blog.

Also Read: Leverage Browser Caching in WordPress

Warning : – Before you start editing functions.php file of your theme, make sure to back it up, In case something goes wrong you can restore it back to make your blog working. 

Steps to Defer Parsing of JavaScript in WordPress

  1. Open up the functions.php file in your theme folder either via hosting panel or WordPress editor.
  2. Add up the following code in functions.php file.
  3. function defer_parsing_of_js ( $url ) {
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' async onload='myinit()";
    }
    add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
  4. Save your files and check your blog performance.
  5. In most of the cases this works great, but if this is breaking your theme, you should remove the added code to revert.

Thank you for reading this post and keep connected to Tech Arrival to continue enjoying beautiful posts. Share your views about this post in the comment section below. If you still have any query, throw it in the comment section.

If you find this post helpful, don’t hesitate to share this post on your social network. It will only take a moment and also it is quite easy and useful for others.

Speak Your Mind