Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

md_imran's avatar

How to remove unused JS?

Hello Dears,

..../landing-critical.js?id=186d63f8d2297677a0f1a599114ba49c%20defer JS (per function)	93 244	53 186 57%	
....jqueryjquery.min.js?id=8fb8fee4fcc3cc86ff6c724154c49c42%20defer JS (per function)	89 456	31 588 35.3%	
JS (per function)	59 950	9391.6%	
.../jquery-modal/jquery.modal.min.js?id=a3c73f5af9f3f18fea45b4181a754d03 JS (per function)	4 893	76215.6%	

I have 53%, 35% unused javascript. How can I ignore that. I use webpack mix and laravel 8.

0 likes
8 replies
Sinnbeck's avatar

What you are referring to is called tree shaking. Without having seen any of your js, it's hard to give suggestions. But if you Google that term you should find several guides

md_imran's avatar

@sinnbeck I just simply reduce unused js file in laravel.

image links: https://ibb.co/4PCshNL

We using laravel mix and purge for css. but I want to purge js as well. Kindly help is this case, please.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@md_imran Yes but it does not work quite the same as css. Css is simple as it simply checks if the class is in use. Js is more complex and require that you tell it exactly what you want. This is what is called tree shaking as I mentioned before.

I dont think there exist a purge-js plugin (I have never seen one)

md_imran's avatar

@Sinnbeck Thanks already. Can you suggest me how can I use tree shaking for js in laravel?

Please or to participate in this conversation.