How to Defer Parsing JavaScript Files in WordPress

(Last Updated On: May 20, 2014)

It is a series article about solving problems from WordPress in order to speed up WordPress blogs. In this article, you will learn to solve how to defer parsing JavaScript in WordPress. The other similar WordPress speed up solved issues can be found here. What actually Defer parsing of JavaScript does? It reduces the initial page load of your page.

If you are looking to boost up your blog add the following code snippet in your WordPress theme’s functions.php file before closing PHP tag ?> (if there is one):

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 );

Once done. Try testing your WordPress blog using online website page speed testing tools. Comment below if you have any question..

7 comments

  1. Hi Muhammed Bhai,

    Thanks for the Awesome tutorials on your blog !

    I have put the same code on my websites function.php file and the end result of the defer parsing of Javascript score in GT Metrix is F 0… Can you please let me know, what is the mistake I am making.. !

    Regards,
    Aashish

    1. Maybe your theme doesn’t support the defer parsing JavaScript coding. Ask your theme developer and I hope you will get the exact answer. Thanks.

  2. That’s really amazing article shared by @Muhammad Haroon brother. I love it and it really helped me to increase the page speed of my site.

    Thanks for sharing.

  3. Thanks for the tutorial. I used some of the information from this article to speed up my wordpress blog. Works better than optimization plugins 😛

Leave a Reply

Your email address will not be published. Required fields are marked *

nineteen + eight =