How to Defer Parsing JavaScript Files in WordPress
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..
If I use the plugin speed buster Pack Do I have to use this code too ??
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
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.
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.
Works like a charm. Thanks for the hint. My site speed increased
Thanks for the tutorial. I used some of the information from this article to speed up my wordpress blog. Works better than optimization plugins 😛
I know that’s why I shared this defer parsing js piece of code on my blog. thanks for stopping by.