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 ...
Get Closure: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.