How to Defer Parsing of JavaScript in Magento 2

How to Defer Parsing of JavaScript in Magento 2

by Van Nguyen

Site speed is one of the most important issues every store owner always takes concerns for the best solutions to optimize it. If your Magento 2 website performs slowly and forces customers to wait so long for loading content or products, this is a big disaster for customer shopping experience. As a consequence, you will lose a lot of potential customers who visit your stores and immediately leave away due to a bad experience. In this blog post, we will introduce you a new solution to and quickly speed up Magento 2 websites called defer parsing of JavaScript.

What is “Defer JavaScript” in Magento 2

According to GTMetix, when loading a page, the browser normally loads from top to bottom of the page for entire content. However, there is a problem that this process takes more time to load because the browser has to load content in all “script” tags. Therefore, to reduce loading time in this case, we need to minimize the amount of JavaScript by deferring Javascript loading until it needs to be executed. It means that the browser will first load everything except for JavaScript and JavaScript is only processed when loading these things is completed.

Benefits of “Defer JavaScript” in Magento 2

It is obvious that deferring javascript in Magento 2 or any other platform helps to reduce loading time and speed up websites to bring better shopping experience for customers. Therefore, when you test your website with some tools such as Google Page Speed or GTMetrix, and so on, your speed score is higher than before as well as defer parsing of the JavaScript score is considerably improved.

Besides, higher page speed is a very good factor to help your website to get higher ranking on search engine result pages. For example, Google has recently announced that starting in July 2018; Google will finally use mobile page speed as a ranking in their mobile search results. This is the reason why it is more and more necessary to optimize site speed for Magento 2 websites. 

How to Defer Parsing of JavaScript in Magento 2

To defer parsing JavaScript in Magento 2, it has become easier and more simple than ever with Magento 2 Defer JavaScript extension. Instead of manually making code changes, this module automatically puts all JavaScript at the bottom of the page to be lastly loaded. Therefore, everyone can defer parsing of Javascript for their Magento 2 website even when they are not specialized in Information technology.

  • Defer JavaScript till the last moment

Now let’s check some interesting tests of a website between Before installing Magento 2 Defer JavaScript and After installing

Test Defer parsing of JavaScript Magento 2 with GTMetrix tool

Defer parsing of JavaScript grade: According to GTMetrix, it is good enough for a website if defer parsing of JavaScript average score is 69%. The higher and higher this score is, the better and better the website is performing.

+ Before installing Magento 2 Defer JavaScript extensionMagento_2_defer_jajascript_-_before_installing

+ After installing Magento 2 Defer JavaScript extension: after install magento 2 defer parsing javascript-gtmetrix

As you can see, after installing the module, Defer parsing of JavaScript is a maximum number, which proves the efficiency of this extension in delaying JavaScript loading and speed up websites.  Frontend Demo

Test Site speed with Google Pagespeed Insights

+ Before installing Magento 2 Defer JavaScript extension: 

defer-javascript-magento-2-extension-before-google-speed

Before installing Magento 2 Defer Parsing JavaSript

+ After installing Magento 2 Defer JavaScript extension

defer-javascript-magento-2-extension-after-google-speed

Installing Magento 2 Defer Parsing JavaSript

This extension helps not only defer parsing JavaScript but also defer Iframes effectively, which contributes to reduce loading time and improve site speed.Download now

  • Exclude specific controllers, paths, and even homepage so that they are not affected by deferring JavaScript.  

    Magento 2 defer javascript - exclude

    Magento 2 Defer JavaScript extension excludes paths, controllers and homepage

    Backend Demo

Conclusion

Magento 2 Defer Parsing of JavaScript is a smart solution for every website to quickly optimize site speed and reduce loading time. Therefore, it plays an essential role in improving customer shopping experience and raising higher ranking on SERPs for Magento websites. 

Magento-2-defer-javascript

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.