How To Fix Defer Parsing Of JavaScript In WordPress
Let’s learn how you can remove the warning of defer parsing of JavaScript in WordPress while checking your page speed in speed tools like webpagetest, GTmetrix, Pingdom, and Google PageSpeed Insights. It’s very important to defer the JavaScript file from your website in order to increase your website speed.
Defer parsing of JavaScript means loading the JavaScript file only after all the HTML and css file gets loaded completely. They are many reasons we should defer javascript loading. But mostly almost all people take speed into consideration for deferring the JavaScript files. JavaScript files are placed between the head tag of our website and when the browser makes calls to all files it’s sent in its given sequence. As Google asks us to prioritize above-the-fold content that can only be done by deferring all JavaScript files and Eliminate render-blocking JavaScript and CSS in above-the-fold. To enhance the speed Google launched amp (accelerated mobile pages ) which loads without javascript files and now a days it’s important for all websites.
The benefit of Defer parsing of JavaScript.
- Increases user experience by loading the website in milliseconds.
- Boost your SEO ranking.
- Google Bots will crawl your website faster
You may be interested in Leverage Browser Caching, Enable Gzip compression caching plugin
You can defer javascript files by 2 methods:
- Without plugin
- With plugin
Without plugin (Only For WordPress users)
For that, you need to log in to your wp-admin. Then click over appearance then theme editor. Inside that find the Function.php file and paste the following code
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 );
By using plugins
There are many which can help you fix your warning For example
- Wp rocket
- Comet cache
- WP Deferred JavaScripts
- Autoptimize
- W3 Total Cache
- Speed Booster Pack
- Wp fastest cache
You can use any plugin out of 7 plugins all are awesome and created by masters. But Here we will learn how you can fix the warning by using autoptimize plugin
Method 1 – Now you need to install and activate the autoptimize
After installation, move to Go to the setting tab of the javascript option and check aggregate Js- file. and click save.
Note – This is the mild deferring of js files Doing forced can break js file loading
Apart from this, you can even use async
attribute in for fixing the warning of gtmetrix and Google PageSpeed Insights for that you can use the below mentioned this plugin. By using async
attributes you can even add control over the JavaScript file which you are not hosting for example – https://www.google-analytics.com/analytics.js or https://apis.google.com/js/platform.js. Even some time so many of us face issues with this file like js/jquery/jquery.js?ver=1.12.4 while deffering https://www.gomahamaya.com/wp-includes/js/jquery/jquery.js?ver=1.12.4. For that, we need to use async
attribute
Method 2
Async JavaScript
By using the async JavaScript plugin You can eliminate render-blocking. This plugin will greatly influence your page speed with greater search engine ranking by enhancing user experience Now bingo no more warning in the speed check tool and your website speed will touch sky.
So after installing the async JavaScript plugin. Click on setting
Then enable async javascript and in the method type also select async.
Now click and save
Method 3 –
Wp-rocket is a premium caching plugin but in my idea, it’s worth buying. Wp-rocket is used by almost of tech companies.
After installing the plugins move to the File Optimization tab. And their inside your will find JavaScript setting
Now inside that tab select minify JavaScript file. Then select the load JavaScript deferred
Method 4 –
Install and activate plugins Speed Booster Pack. Inside speed booster plugins setting move on to Advanced tab and turn on Defer parsing of JS files button and click save
Now hopefully out of 5 Method, one method will work for fixing Defer Parsing Of JavaScript In WordPress. If you are facing an issue with youtube videos then you should try this blog
Greetings Rahul,
Hope that you are well & safe.
Followed method 4 (Speed Booster Pack) and it resolved my issue instantly. The PageSpeed Score on GTmetrix jumped from 63% to 91%.
Thank you very much for sharing all this information. Truly appreciate it.
Sincerely,
Philippe