Google's Closure Compiler
Optimising page load times usually comes down to compressing the content of the website, like compressing and minifying .css or .js files as well as the page and images themselves. While all these have become trivial tasks even for dynamic pages, with different tools to do the compression as well as the plethora of tutorials out there, Javascript was allways a pain. Most websites our days are using frameworks such as jQuery or Mootools to provide a better user experience, but even minimized and compressed they do take a lot of space. Also, there's a lot of uncompressed code that was written by the web page developer that is served as is or in the best case scenario with a standard compression and minification level.
Google goes beyond that and provides the Closure Compiler, a tool that not only minifies any Javascript file, but also removes dead code, issues warnings and errors regarding the script and in the most advance form, it rewrites the code so it's more efficient and browser-compatible. Note tough, that this feature can generate code that doesn't run, so it's advisable that you always test it upfront. It's yet another amazing tool from Google that most web developers need on every project. Also, the tool comes in two flavours, either as a stand-alone, command line Java app or as a web service.
Best part, it also has a RESTful (Representational State Transfer) API, which means you can use it with the programming language of choice, for webpages where you want to compress your own Javascript code it only makes sense to use a server-side language such as PHP. All you have to do is make an HTTP POST request including a few parameters like the actual JS code or file URL and level of compression and you're done.
To make everything perfect, Google also offers Closure Inspector, a Javscript debugger for Firebug, which can revert the minified code and show you the line where the error resides in the original source file, among other cool features.
Enjoy using Closure Compiler and Let's make the web faster!
Related links
- Closure Compiler (online service)
- Closure Compiler API documentation
- Closure Inspector (Firebug extension)
You can visit the author's website at blog.hazardousgaming.info
There is a similar article, click here for list.
| There are no comments on this article. Be the first to say your opinion. |






