Best Way to Defer Parsing of JavaScript in WordPress


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 the bottom of the page won’t help you solve this Defer JavaScript problem. Facebook like a 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 the 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. These plugin settings are very complex and difficult to understand options. In the end, you will get the best result in page load time with this W3 total cache plugin.

Leave A Reply

Your email address will not be published.