O'Reilly logo

Closure: The Definitive Guide by Michael Bolin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Advanced Compilation

The previous chapter explained how to get up and running with the Closure Compiler and how to minify JavaScript using Simple mode, but this chapter will focus on how to get greater code size reduction and better compile-time checks by compiling JavaScript using Advanced mode. In Simple mode, the Closure Compiler minifies, or reduces the size of input JavaScript primarily by removing whitespace and renaming local variables. With a few caveats, no assumptions are made about the input to the Compiler. In Advanced mode, the Compiler uses more sophisticated techniques in addition to those employed by Simple mode to reduce code size. In using these techniques, the Compiler makes a number of assumptions about the code being compiled. Knowing the assumptions that the Compiler makes is the key to understanding Advanced mode.

It is important to fully understand Advanced mode before enabling it for several reasons. First, it will help ensure that you have made all the changes to your code to satisfy the restrictions of Advanced mode. Second, if you encounter a bug that exists only when your code is compiled in Advanced mode but not in Simple mode, it will give you a better idea of where to start looking to identify the error. Third, it will help you write your code in a style that can be best optimized by the Compiler.

This chapter aims to explain each transformation that the Compiler performs in Advanced mode in isolation from one another. This reflects the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required