If your JavaScript is not very dynamic in nature, you can give the Closure Compiler a shot.
Collect all your JavaScript in one place (including jQuery, plugins, other libraries, everything) and send it to gcc using the advanced compilation option.
This will remove all unused functions that could potentially violate your code. I would recommend this only if you have test cases, or your JS is small enough to fully verify manually.
A simple example of optimization performed by the compiler is:
function hello(name) { alert('Hello, ' + name); } hello();
will be reduced to:
alert("Hello, undefined");
since thatβs all that happens mostly.
Anurag
source share