I recently played with a terrific tool from Google that does some code optimization and partial execution, for example, it would require something like:
//Just an alias for an elementByID selector function $(bar){ return document.getElementById(bar); } //Call the selector alert($("foo").value);
And shorten it to alert(document.getElementById("foo").value); , which is quite surprising in terms of optimization.
I just explain this because I thought this concept worked for large libraries such as jQuery, which basically tries to distract a bunch of things that JavaScript does, like picking by identifiers, for example.
In a quick test, I downloaded the entire jQuery production file to the compiler and added one bit of text at the end: alert($("#foo").val());
And quite tragically, the compiler could not match the jQuery design and the result with a simple example that I had above, but my output is about 85 KB of text with alert($("#foo").K()); stuck in the end. Basically, I only had a small code, and it did not use the excellent function demonstrated above.
So my question is: if I end up using the library, how can I code so that the closure compiler can simplify my code for it with native JS (or something more efficient than 85kb of unused code)? Alternatively, what design should someone take if they want to create a small library that plays well?
source share