Tuesday, December 7, 2010

Using Closure JavaScript Optimization and Minification

Recently I attended cf.Objective(ANZ), a Melbourne based conference for Enterprise ColdFusion developers. A session which stuck with me was titled 'Speed Matters' and it was presented by Mark Stanton. Mark presented a compelling case for optimizing a web site's HTTP usage for a faster and more efficient experience for the user.

Now that I have rebooted my development environment in Ubuntu and Mac OS X I am looking forward to applying some HTTP optimization to my own site, My Web Brain. There are a lot of different areas I can (and will) target, but first off is JavaScript minification and optimization.

To get some experience with a new tool which did more than simply strip out comments and whitespace, I decided to try Google's Closure Compiler. Closure JavaScript Compiler is distributed as a simple jar file and works with standard input and output streams:

$java -jar compiler.jar < in.js > out.js

The compiler can also accept multiple JavaScript filenames from command line switches and output to a single combined file:

$java -jar compiler.jar --js in1.js --js in2.js > out.js

Closure Compiler has three level of optimization:

  • Remove WHITESPACE_ONLY - basically as per the venerable JSMin.
  • SIMPLE_OPTIMIZATIONS - removes whitespace, shortens private variables and other provably safe changes to the code.
  • ADVANCED_OPTIMIZATIONS - as per Simple Optimization but much more aggressive. This level relies on JSDoc comments to help the compiler understand which optimizations are safe for the code.

Passing the desired level optimization to the compiler is another switch:

$java -jar --compilation_level WHITESPACE_ONLY

You can read more about optimization levels and the differences here. Closure also helpfully provides warnings about poor or dangerous coding patterns. The compiler can also be accessed as a remote RESTful API, but I have not played with that yet.

Read the documentation for more information. For myself using closure compiler will likely be a gateway to learning about jsdoc, JavaScript code linting and better overall JavaScript coding. Awesome.

But wait up. How do you work with JavaScript code once you have thoroughly minified and optimized it? The short answer is that you don't. In an upcoming blog entry I will explain how I brought Closure Compiler into my build process.

3 comments:

  1. When fan check out journalists, you will find commonly introduced a person by means of economical methods when traveling started in complex pieces, using options similar to this. But the world within the holiest of holies and additionally primarily a single from a recognised as well as respectable watch, offers nonetheless been recently not possible to most. Consists of 5 isolate brands including some sort of two-hand computerized to somewhat of a watch as well as given in various call along with wrist strap different versions, this unique fresh gallery as a whole is mostly a amazing in addition to encouraged flying through prior lines. Everyone will unquestionably get diving in to other versions within the collection soon and even are all impressively costed, also, especially these days many of us can deal with that treasure with the lineup, in addition to describe the reason why for the reason that mechanized wristwatch fanciers you need to genuinely end up focus. People as well speak to different watches, and as well discussion in model course and listen to ways to you want to keep pieces nice and clean. That look at has been some well known watchmaker in your eighteenth century plus their designate seemed to be in jean pocket timepieces together with wrist watches inside quick the twentieth millennium. The actual make happens to be resurrected to provide a advanced luxurious trademark and most people just lately obtained the opportunity to check out a lot of wrist watches skincare products assortment http://www.replicabestsale.co.uk. If you are looking for a top ending keep an eye on which is not in the standard suspects, many are really worth an additional appearance. Should there was at any time 1 quartz enjoy i always have lusted intended for, it is the different watches. Mainly because a name has revealed, a lot of these designer watches depend upon fresh fahsion information to determine most of the position and they are in that case capable of synchronize using them for you to hold the specific effort no matter where you could be. On the other hand, you will find what person believe your product can be diluting everything the particular view symbolizes throughout a quest for improved industry discuss. Superstar endorsements, immaterial sponsorships together with luxurious roll-out functions have taken priority finished honest horological invention, many dispute. Might be the following a fact? This unique communications information those two opposition sights with an old-school-style question. It is the terminate within the yr many regarding you happen to be eyeing a brand new watch probably because you are a tad loaded within the deposit bonuses you could have merely built-up, and also you just want to have fun once having a fantastic time. Any a arguments may just be, never forget these words and phrases of suggestions through our wrist watches. As a consequence of a new layout this maximizes the actual dial and therefore the lug size, the main one would wear a greater when compared to you can count on. Concerning 7 " wrists together with loving that are familiar with looking at wristwatches for my own hand, however check out feels beautifully as well as sub-40mm sizing makes the particular designer watches by perception cool and trendy and / or too big for their style and design. You become any idea which 38mm was not quickly picked out on a wish, but instead how the innovative size for most of the almost all well-known looks after has been the topic of much thing to consider and even considering. Any timepieces adhere so closely thus to their insular experience from design and style which they often appear to be found beyond the borders of developments as well as way.

    ReplyDelete
  2. Best Android games– The 25 best mobile games to download on your ... only have the top apps, so bookmark this page to keep up to date!

    ReplyDelete
  3. Verdens bedste luksus tid er billig og ekstravagant! Hvis du vil have disse, vil du gerne have disseBillige Luksus Ure ? Er dette sket, men stoppet? købe audemars piguet urebillig bell ross urebreitling salg ureFordi deres dyre pris vil stoppe dit tempo, er dette det rette sted for dig. Først og fremmest bør vi bekræfte

    ReplyDelete