I've recently been playing with the awesome tool from google that does some code-optimization and partial execution, for instance it would take something like:

//Just an alias for an elementByID selector function $(bar){ return document.getElementById(bar); } //Call the selector alert($("foo").value);

And shorten it into alert(document.getElementById("foo").value); , which is fairly awesome from an optimization viewpoint.

I'm only explaining this because I would have thought this concept works for larger libraries such as jQuery, which basically attempts to abstract away a bunch of things JavaScript does, like select by IDs.

In a quick test, I loaded the whole jQuery production file up to the compiler and appended a single bit of text at the end of it: alert($("#foo").val());

And quite tragically, the compiler wasn't able to map through jQuery's design and result with the simple example I had above, but rather my output is about 85kb of text with alert($("#foo").K()); stuck on the end. Basically, I just have minified code, and didn't take advantage of the awesome feature demonstrated above.

So my question is, if I do end up using a library, how can I code in such a way that closure compiler is able to simplify my code to it's native JS (or something more effective than 85kb of unused code)? Alternatively, what design should someone take if they wanted to make a small library that plays nice?