This previous question asked how to eliminate dead code but didn't seem to answer the central question: find dead JavaScript code?
I am trying to minify a set of 12 javascript files that include jquery and a couple of other libraries. I am confident that most of jquery is unused.
The current compile line is:
java -jar compiler.jar --language_in ECMASCRIPT5 --compilation_level ADVANCED_OPTIMIZATIONS --js *.js --js_output_file liq-min.js
It reduces the size of the code from 240k to 176k, but since 90k is jquery, it should have been able to do a lot better.
Specifically for google closure, is there any way to define a set of initial function calls, and eliminate all functions that are not called? Obviously eval and other string related issues mean we would have to manually set the list, but what is important is to strip out the bigger libraries being called.
Also, closure shrinks local variable names but not global function names. Is there any way to do that as well? If necessary, I am prepared to add a string substitution pass at the end, but that is not ideal.
In other words, is there any way to get closure to convert:
Calendar.foo()
function foobar() {...}
into
C.f()
function f2() {...}
Given that I am entering all the code into the compiler, there is no need to worry about external references to these functions. In other words, this is not a library, it is an application and the only function calls needed are those that are used.