Magento 2 Defer Parsing of JavaScript Pro

Table of Content

  1. Extension Installation Guide
  2. Configuration
  3. Before Implementation of Defer Parsing of JavaScript
  4. After Implementation of Defer Parsing of JavaScript

 

  1. Extension Installation
      • Find the Composer name and version of the extension in the extension’s composer.json file.
      • Login to your SSH and run:
        • composer require meetanshi/magento-2-defer-javascript --ignore-platform-reqs
      • Enter your authentication keys. Your public key is your username; your private key is your password.
      • Wait for Composer to finish updating your project dependencies and make sure there aren’t any errors.
      • To verify that the extension installed properly, run the command:
        • php bin/magento module:status Meetanshi_DeferJS --ignore-platform-reqs
            • By default, the extension is probably disabled.
            • Enable the extension and clear static view files:
        • php bin/magento module:enable Meetanshi_DeferJS --clear-static-content
        • php bin/magento setup:upgrade
        • For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
        • For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
        • php bin/magento cache:flush

 

  1. Configuration
    For configuring the extension, log in to Magento 2, move to Stores > Configuration > Defer Parsing of JavaScript where you can find various settings to enable the extension.
  • Defer Parsing of JavaScript: Enable Defer Parsing of JavaScript extension.
  • Exclude Home Page: Set YES to exclude the home page from the defer parsing of JavaScript.
  • Exclude Controllers: Add controllers to exclude from defer parsing of JavaScript.
  • Exclude Paths: Enter paths to exclude from defer parsing of JavaScript.


  

  1. Before Implementation of Defer Parsing of JavaScript
    If you check any low-speed Magento 2 website in Google PageSpeed, you can see the recommendation for Defer Parsing of JavaScript which is having the low grade as shown in below image. 


  

  1. After Implementation of Defer Parsing of JavaScript
    After implementation of Defer Parsing of JavaScript in Magento 2 store, you can see the better grade in Google PageSpeed for JavaScript as shown below. All the excluded page, controllers and path will no longer deferred parsing of JavaScript. The improvement of grade helps in improvement of website load time.