Optimize Javascript files with Google Closure compiler

2009
06
Nov

Google has released / open sourced one of its internal tools, the javascript closure compiler. The closure compiler is used to optimize javascript files. It works by analyzing the code and removing redundancies and shortening variable names.
This tool can be used to compress javascript files, (similar to the famous packer), results in lesser code to download, execute, obfuscation and faster user experience.

Since most web 2.0 or 3.0 applications uses a lot of javascript usually jQuery library or the YUI (Yahoo User Interface) Library to make RIA (Rich Internet Applications), this can be a very handy tool to improve Performance.

The example code shows converting the following script from

function hello(name) {
  alert('Hello, ' + name);
}
hello('New user');

to
function hello(a){alert("Hello, "+a)}hello("New user");

It removes whitespaces, and shortens the variable names.

Closure Compiler Appspot ScreenShot

A Few numbers :

For JQuery-UI Javascript :
Original Size 298.5KB (70.93KB gzipped)
Compiled Size 167.17KB (42.47KB gzipped)
Saved 44.00% off the original size (40.12% off the gzipped size)
For YUI Javascript :
Original Size 118.35KB (27.23KB gzipped)
Compiled Size 24.38KB (8.12KB gzipped)
Saved 79.40% off the original size (70.17% off the gzipped size)

Closure Tool Links :

Other Similar Tools


Similar Posts
Related Searches




Comments

Post new comment

The content of this field is kept private and will not be shown publicly.