Reduce unused JavaScript - algoliaBundle.min.js

As per this documentation, we installed Algolia extension in Magento 2 site. We are auditing the site using google page insights and it is suggesting to Reduce unused JavaScript on algoliaBundle.min.js.

Please check this screenshot for your easy reference.

Please check and advise us. Thanks in advance.

Hi @bilalusean.a_7, Have you enabled the Algolia autocomplete and instantsearch in your extension? They will both require the algoliaBundle.min.js.

@cindy.cullen Thanks for the response. Yes, we enabled Algolia autocomplete and instantsearch. We are using both. is there anyways to reduce the unused code?

Speaking for the magento integration here, Algoliabbundle includes it’s own copy of jQuery, which might very well mean you have it loaded twice. I’m still waiting for a solution to use an already loaded jQuery. That would reduce code size wire a bit already.
Also instant search and all it’s requirements in the bundle are loaded on all pages, but really only need on catalog search and category pages. So ideally, the bundle would be spilt in two files.

@alex1 Thanks for sharing your idea. I hope someone from the Algolia team will provide the solution to reduce unused code from the algoliaBundle js.

@cindy.cullen any updates on this?

What you can do is the following:

  1. remove the reference to the existing algoliaBundle
  2. change the code to use existing jQuery imports if you already have those
  3. download the bundle generator:
  4. remove the parts of the code you’re not using
  5. create a new bundle
  6. reference the new bundle in your phtml

@bilalusean.a_7 If you succeed with this please let me know. I tried a while ago, but failed to set that up so it doesn’t include jquery!