Reduce Unused JS(scripts) For Magento 2

It is all about unused js, that are not in use or that are unwanted for your site and block the site speed.

1.Identification

Tools like GTMetrics, Lighthouse, Page speed insights
reduce-unused-javascript

2. There are two Methods:

2.1 Override the files
We need to find out what files are not being used and delete them,
1. Just because the script is not used somewhere doesn’t mean it’s not used somewhere else.
2. Scripts can have very unclear dependencies, even not-so-obvious ones.
3. Remove Unused Scripts and Move the Rest to the Bottom
Override-the-files
Example
1)File Name: colorpicker.js
Search the file path and need to be 0 byte file, override the file according to a path like.
Path:
app/design/vendor/theme_name/Magento_ui/web/js/lib/knockout/bindings/colorpicker.js
2.2 Remove the scripts according to reference Blocks
Example
Authentication-popup- Block
Used to display a popup if you require login to checkout, case by case dependent but we can get rid of it, for now if needed maybe a redirect with a message might be enough.
Removing Block Through (XML)- These are the main XML files,
  • cms_index_index.xml (Home page)
  • Catalog_catagory_view.xml (Category/Listing Page)
  • Catalog_product_page.xml (Product page)
Removing the authentication-popup- Block
< referenceBlock name=”authentication-popup” remove=”true” />
No. of JS File Removed like
  • adapter.js
  • authentication-popup.js
  • buttons.js
  • captcha.js
  • captchaList.js
  • defaultCaptcha.js
  • effect-blind.js
  • form.js
  • login.js
  • loginCaptcha.js
  • messages.js
  • refresh.js
  • resolver.js
  • validate-review.js
  • spinner.js
  • Ui-messages-mixin.js

Latest Posts

One Comment

  1. Packers & Movers March 16, 2023 at 8:33 pm

    informative

Leave A Comment