Closure Compiler by Google

Posted at

Closure Products Logo (including Closure Compiler) Google Code Lab Logo

Google's Closure Compiler Service is basically a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

tools that are recommended to be used along with it are:
-Closure Inspector Add-On for firefox.
-Firebug JavaScript debugger.

there are two ways using the Closure Compiler through command-line, and the online service,

first one, is by using the recent build, that can be download from this URL:
to use the advance attribute of the compiler you might want to use the following command:
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --warning_level VERBOSE  --js 1.js --js_output_file 2.js

rem where 1.js is the original javascript file.
rem and 2.js is the name for the output file.

second way is using the online service at
closure-compiler screen example by Elad Karako

Once the compiler has been rendered a fixed, more compact code (but not exactly readable), you can use it as it is (highly compressed), or another good option is to run it through the Javascript unpacker and beautifier by Einar Lielmanis, to make it more readable, or, "human-friendly".