What is the Closure compiler?

If you have no idea what I'm talking about, check this out: http://closure-compiler.appspot.com/home (this is a JavaScript minifier)


On their website they declare the following:

The Closure compiler compiles JavaScript into compact, high-performance code. The compiler removes dead code and overwrites and minimizes what remains, so that it loads and runs quickly. It also checks syntax, variable and type references, and warns of common JavaScript traps. These checks and optimizations help you write applications that are less error prone and easier to maintain.

But can someone really explain in detail what this Closure compiler does for my code?

+2
javascript
source share
2 answers

The Closure compiler will compile your code and follow standard methods for optimizing your code.

The resulting code may or may not have similarities when viewed superficially, but usually works the same way.

+2
source share

https://developers.google.com/closure/compiler/docs/compilation_levels

ADVANCED_OPTIMIZATIONS conversions include:

  • more aggressive renaming:
    Compiling with SIMPLE_OPTIMIZATIONS only renames the parameters and variables inside the functions. ADVANCED_OPTIMIZATIONS also renames global variables, function names, and properties.

  • dead code removal:
    Compiling with ADVANCED_OPTIMIZATIONS removes code that is supposedly unreachable. This is especially useful when combined with large libraries. If you use only a few functions from a large library file, the compiler can remove everything except these functions from its output.

  • global insertion:
    Compilation with ADVANCED_OPTIMIZATIONS replaces some function calls with the body of the function. This conversion is known as inlining. The compiler only has built-in functions when it determines that inlining is safe and saves space. Compiling with ADVANCED_OPTIMIZATIONS also includes constants and some variables when the compiler determines that it can do it safely.

+1
source share

All Articles