Adding External Javascript
Klevu adds external Javascript files to your site to enable Klevu Theme JS to work as expected. The core file is always added when any Klevu solution is enabled. Other files include Recommendations, Category Navigation, SRLP and Quick Search.
The majority of the files added by Klevu are required at load time and are added to the head via the Magento secureRenderer like so.
Quick Search however is not required at load time and can be loaded after page load.
We have taken a lead from Hyvä Themes with our approach here adding files to the head after load to avoid blocking the rendering of the page. e.g.
Our implementation can be found in this template file
We loop through all provided links and add them to the head after page load.
Adding scripts to the head in this manner is better for performance however, it does not add those scripts via secureRenderer. External scripts added from klevu.com are whitelisted via etc/csp_whitelist.xml in the relevant modules.
Note: All Klevu scripts are removed from the checkout page by default.
If you require those scripts to be added via the secureRenderer please ensure you inject quick search to the head using the first method.
Layout XML to make that switch:
The example given shows how to make this change in a module. Theses change could alternatively be made in your theme(s).