How to Defer Parsing of JavaScript in WordPress
When you check the speed of your WordPress blog, you may get defer parsing of JavaScript. In WordPress, using Async code and pulling JS code to bottom of page won't help you solve this Defer JavaScript problem. Facebook like box, twitter button, Google + widget and other social sharing buttons will slow down your website speed.
Also see: How to Avoid CSS @Import in WordPress.
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.
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 );
Page speed matters a lot in Google search engine rankings.Use only recommended and useful WordPress plugins.Delete unnecessary plugins and install the best cache plugin like W3 total cache or WP Super cache to improve page load time.Of course, with W3 total cache defer parsing of Javascript hardly.This plugin settings are very complex and difficult to understand options.At the end, you will get the best result in page load time with this W3 total cache plugin.
Paul says
Hi,
I followed your steps, and it worked great.
I am still having problems with wp-includes/js/jquery/jquery.js
Any suggestions?
I used a defer parsing plugin, but added huge size and query string to my website, although defered the file above without issue.
Thanks
Syed Bavajan says
Install Async JS and CSS plugin to completely defer parsing of JavaScript. http://mygenesisthemes.com/async-js-and-css-settings/