Has anyone compiled jQuery against Google's newly-released Closure compiler?
There has been reported huge savings in code size. I'm curious what the benefit is if jQuery was compiled with it.
Has anyone compiled jQuery against Google's newly-released Closure compiler?
There has been reported huge savings in code size. I'm curious what the benefit is if jQuery was compiled with it.
Doesn't Closure just minimize and renames vars? jQuery already has a .min version. Minifying with closure again will probably be minimally helpful and potentially dangerous.
Edit: I just did it.
Compilation was a success!
Original Size: 55.91KB (19.28KB gzipped)
Compiled Size: 54.05KB (18.28KB gzipped)
Saved 3.34% off the original size (5.18% off the gzipped size)
This is on top of the already mined version. There's a demo here: http://closure-compiler.appspot.com/home
I tried with jQuery jQuery 1.3.2
jQuery-1.3.2.min.js 57254 Bytes
jQuery closure compiler 49730 Bytes
-----------------------------------
Reduced by 7524 Bytes
Saved 13.31% off the original size
Saved 10.87% off the gzipped size
Gain of ~7KB
But it also reports 15 Warnings and I didn't test if it still works
With ADVANCED_OPTIMIZATIONS turned off:
With ADVANCED_OPTIMIZATIONS turned on: it doesn't work unmodified. With ADVANCED_OPTIMIZATIONS turned on and everything I can find to export exported... it still doesn't quite wok, and the code is already up to 53466 bytes again (and 18785 gzipped, which is more than the gzipped closured code without ADVANCED_OPTIMIZATIONS) so it doesn't look like a winning proposition.
John Resig reported a bug on recursive functions when he attempted to compile a nightly of jQuery 1.4, so there are a few kinks to be worked out. I wouldn't use a jQuery compiled with Closure Compiler without making sure it passes the jQuery testbed.
http://code.google.com/p/closure-compiler/issues/detail?id=1&can=1#c2
You can find more details on using Google Closure API with ASP.NET at http://www.bloggingdeveloper.com/post/C-Wrapper-for-Google-Closure-Compiler-Compressing-Javascript-Files-on-the-fly-with-ASPNET-and-Closure-Compiler.aspx.
It features a C# wrapper for the tool.
Think I'll wait for Resig and the team to release a new -min or special closured version. I wouldn't want to compress the library find out specific features didn't work or didn't work as expected.
Out of curiosity, I put together a SlickSpeed test of the latest Prototype and jQuery libs, shrunk with YUI and Closure. You can run the tests here.
As others have noted, compiling with ADVANCED_OPT does not work but if someone wants to do the work, I'll be happy to add the results to the SlickSpeed test.
The closure compiler eliminates any code that you don't actually use. The typical web page will only use a small fraction of jQuery functions, so the most benefit will come from compiling your code together with the full version of jQuery.
I used Closure (with ADVANCED_OPTIMIZATIONS) to compress the javascript code for a single-page site that I host and saw a significant size savings over the YUI Compressor. So I started looking into shrinking jQuery for that site as well, since it certainly doesn't use the entier jQuery library.
I get warnings every time I run jQuery through the compiler, mostly pointing out portions of the code that are not used. Even still, the compiled code doesn't work. The primary issue I see is that things aren't being exported properly by the compiler. I was able to easily export functions from my own code by attaching them to the window object, but I have not yet been able to do this yet with jQuery.
The good news is that John Resig is already experimenting with Closure. I suspect that we'll see new releases of both that are compatible in the near future.