I am in the process of milking out every byte possible out of a library i am writing using the google closure compiler.
The library consists of two files:
- The main library file
- The file i use to export my library's methods
I am compiling with ADVANCED_OPTIMIZATIONS using the closure builder, the options i use are in the 'compile' key of this grunt config.
Reading the compiled file i can see a few symbols not being compiled like they should. I even took advantage of this fact and omitted exporting one method, and it got exported (addListener). Other methods only get "uncompiled" if i export them, like the removeListener.
So the compiled code where symbols are exported looks like this:
var k = e;
k.C = g;
var l = g.prototype;
l.addCheck = l.j;
l.check = l.k;
l.addCheckListener = l.r;
l.removeCheckListener = l.s;
l.removeListener = l.removeListener; // why is that?
// taking advantage of addListener not being compressed, i omitted it, so saved
// a few more bytes:
// l.addListener = l.addListener; <----
l.isDone = l.o;
l.isDoneCheck = l.p;
k.C.prototype = l;
window.ss = {
ready: k
};
Why is that happening and what can i do to further optimize resulting code size?
As a bonus question, i created two private methods in an effort to reduce the use of setTimeout and delete in the compiled code. However the compiler chose to inline all the calls i made to these methods resulting in having the uncompressed delete and setTimeout calls multiple times in the compiled source.
e.g.
function rem(obj, key) { delete obj[key]; }
function doStuff() {
var anObject = {key:1};
rem(anObject, 'key'); // 'key' isn't really a string literal in the code
}
This gets compiled to:
function a(){var b={z:1}; delete b.z}
Any tips on avoiding that too?
Cheers