Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript minifier that strips out unused code

Does anyone know of a JavaScript minifer that can detect unused code and strip it out.

Google Closure seems alright but it appears to only compact.

I'm looking for something much more advanced, where it can look through my JavaScript and not only compact but also remove unused code.

Anyone know of such a tool?

The use base being, I use very little functionality of JQuery - what I would like to do is remove from the base/core all the bloat that is unneeded from my use.

like image 426
Henryk Avatar asked Dec 16 '09 05:12

Henryk


2 Answers

Closure Compiler should do the job, from the Closure FAQ

Closure Compiler helps reduce the size of your JavaScript by removing comments and unused code and shrinking the remaining code.

like image 147
Chris Fulstow Avatar answered Oct 05 '22 19:10

Chris Fulstow


Probably not.

The problem is that there's no guaranteed way to figure out what's used and what isn't. Javascript can be used/referenced from HTML, the script(s) could be used with other unknown scripts that use otherwise unused code and eval() blocks may use things you don't realize.

Minify and gzip it and that's enough. If not, cull it by hand (although getting rid of code is a lot harder than adding it in the first place).

like image 40
cletus Avatar answered Oct 05 '22 19:10

cletus