Hello @tapan_sain , As per your question, reducing JavaScript execution time is one of the challenging tasks to do. Slow JavaScript execution can impact your store’s performance, affecting page load times and user experience.
Here are the ways to reduce JS execution time without breaking functionality:
1. Remove and Load App Scripts Smartly
- Defer Non-Critical Scripts- Rather than splitting your js file , you can defer scripts that aren’t necessary for the initial rendering of the page. This way, they’ll load only after the main content is displayed:
- Avoid loading JavaScript globally when it’s only needed on certain templates. Use Liquid conditionals:
{% if template == ‘product’ %}
{% endif %}
This ensures that scripts for specific features only load on the relevant pages, avoiding unnecessary load time on other pages.
- Lazy Load Heavy Widgets
For apps like product reviews, chat widgets, etc., load them after user interaction or when they enter the viewport:
window.addEventListener(“scroll”, function loadReviews() {
const script = document.createElement(“script”);
script.src=“https://review-widget-url.js”;
document.body.appendChild(script);
window.removeEventListener(“scroll”, loadReviews);
});
This ensures that these heavy scripts don’t block the initial page load and only load when necessary.
Alternatively, if you prefer not to handle this manually, I’d recommend trying Website Speedy – a Shopify speed optimization app that automatically reduces JavaScript execution time. It’s quick to set up and includes a 14-day free trial.