In general you would see more of a difference between SIMPLE_OPTIMIZATION and WHITESPACE_ONLY. However in this case the code is so simple that there isn't much of a difference.

So far we see that the output from Uglify is actually better. This is mainly because I've enabled some of Uglify's aggressive options.

ADVANCED_OPTIMIZATION

Closure compiler doesn't really start to get interesting until you enable ADVANCED_OPTIMIZATION. This is where you start to see some amazing results though.

Take a look at the Closure compiled output of the original sample:

alert("Hello there");

As you can tell this is drastically better than any of the other results.
Basically the Closure compiler rewrote the original code to something much smaller. This goes far beyond simple minification since the original code is actually rewritten. Closure was able to analyze the original code and conclude that the outcome is always an alert of the string “Hello there”.

All the other code in between was removed through function flattening and inlining.

It's worth pointing out that these impressive results come at the cost of potentially breaking your application if you're not careful. In some cases Closure might go too far. This is why Closure compiler is often referred to as an export tool.

It's important that you write your code with the Closure compiler in mind in order to benefit from it.

I have another article with some advice on how to successfully use Closure.

If you liked this article, share it with your friends on social media: