The Google Closure Compiler is one of the latest tools released by Google in its never-ending quest for enhanced user experience. Unlike iGoogle and Google apps, the Closure Compiler is not aimed at the end user though. Instead it is one of the suite of tools designed to help Web developers create faster, cleaner code. That's because Google has started including page speed as one of it's ranking criteria, in recognition of the fact Web users don't want to sit around waiting for pages to download.
What does Google Closure Compiler do?
- WHITESPACE_ONLY will remove whitespace and comments.
- SIMPLE_OPTIMIZATIONS the default setting, renames local variables as well as whitespace and comments.
- ADVANCED_OPTIMIZATIONS will further compress code by renaming symbols and global variables, but could break scripts which are spread across multiple files unless all code is compiled together and other steps are taken to ensure calls to third party scripts are protected.
How can I use the Closure Compiler?
It can be run from the User Interface (UI) at http://closure-compiler.appspot.com/home, or by connecting a Web page of your own directly to the application programming interface (API). See Getting Started with the API and Closure Compiler Service API Reference to get started compiling your own code. You can also download the Closure Compiler Application to run on your own computer as a java command line utility.
Issues with Closure Compiler
Although the Closure Compiler turns out cleaner more efficient code, there have been concerns raised among Web developers that it may deter new developers from learning about coding by viewing the source code of web pages and de-constructing the scripts, as discussed on webmonkey.
The problem is where human developers tend to name variables in a self explanatory manner, to make keeping track of them easier, such as “UserName”, the Closure Compiler strips these names out replacing them with a single letter “a” making the output less human friendly. Where the ADVANCED_OPTIMIZATIONS option is used and function names and symbols are replaced with shorter code, the task of deciphering them becomes even harder for the inexperienced but curious coder. It's a trade off. Machine friendly, faster code is inherently less human friendly.