[the pageforest.com blog] Google's new Closure JavaScript optimizer

1 view
Skip to first unread message

Mike Koss

unread,
Nov 6, 2009, 7:06:43 PM11/6/09
to pagef...@googlegroups.com

I'm pretty excited to see the release, today, of Google's Closure JavaScript compiler.

Closure goes way beyond a simple JavaScript minifier. It can do things like unwind function calls, and replace them with the body of the function. It also changes local variable names to single characters.

You can either download the compiler locally, or use their web service (though the UI or via a REST API). Here a sample of how aggressively Closure can reduce your code size:

function Foo(string)
{
 alert(string);
}

Foo("hello");

In Simple optimization mode this yields:

function Foo(a) {
 alert(a)
}
Foo("hello");

In Advanced mode this compresses to:

alert("hello");

I'm still learning how to use Closure optimally for some of my code. For example, in Advanced mode, my JavaScript Namespace code is pretty severely compressed. First, Simple optimization yields:

While Advanced Optimization saves a few hundred more bytes, but mangles some variable names that should be left alone as external method names:



--
Posted By Mike Koss to the pageforest.com blog at 11/06/2009 03:00:00 PM
Reply all
Reply to author
Forward
0 new messages