Can I delete unused JS?

17 1 15

We have A LOT of unused code slowing down our site. Using dev tools, I can see all the code not being used, its almost all in the index.js. Can I just delete it or will that mess something up? 


Shopify Partner
153 17 93

This is an accepted solution.

Your are asking if you can just delete index.js, right? I don't know your site's URl or theme or know what is in index.js so I can't give you specific advise on that.

If PSI says 90% of index.js is not being used, it is possible there is still 10% of that code doing something, like currency changing or whatever. 

It is also possible that in the future you might want to enable a feature that is not currently being used, or that there are features that only activate for certain users and thus are not activating for pagespeed insights. So I would reccomend not deleting index.js and instead carefully going through index.js and refactoring the code to conditionally load code depending on what features are on the page using dyanmic imports (if you don't care about IE 11 users, which you shouldnt)

Available for freelance. I specialize in speed improvement and theme development.
Shopify Partner
134 10 71


I'd have to agree with @oreoorbitz answer. Even though there may be a ton of unused code coming from index.js, some code is being utilized within that file or potentially on other pages.

Deleting the file will likely cause errors and remove/break whatever functionality is coming from the 10% of utilized index.js code.

The best solution is to manually go through your index.js file (only recommended if you're familiar with code, if not, I'd hire a developer) to see what blocks of code could be removed and which need to stay. Unfortunately, there's not a simple solution for this issue.

Best of luck!

Developer at SpeedBoostr (Shopify optimization and dev agency).
Try out our Shopify Analyzer (free performance analysis tool).
Check out Order Automator (app that auto tags + fulfills orders, and more automation)
More Apps: Theme Scientist (A/B testing tool), Tip Jar (add a tip button to your store), File Optimizer (optimize CSS, JS, Liquid)