0

I am using closure compiler to minfiy and concatenate my scripts and I would like to use the ADVANCED_OPTIMIZATIONS flag to get even more minifying magic out of it. However some of the scripts I have create warnings when I use this flag and do not function. I would like to instead of passing that one flag step through a bunch of smaller options and see which one breaks it and maybe I wont get 100% the size reduction being offered but closer.

Are there any smaller individual flags to pass to google closure compiler options to turn on individual features of the 'ADVANCED_OPTIMIZATIONS' flag?

BillPull
  • 6,853
  • 15
  • 60
  • 99

2 Answers2

0

The short answer is "no".

The jump between SIMPLE_OPTIMIZATIONS and ADVANCED_OPTIMIZATIONS may seem huge, but it really comes down to two major issues:

  1. dead code elimination
  2. property renaming

For both of these items, the compiler needs the same set of information in order to do this correctly. It needs:

  • Details on every reference to your code - both within the code itself as well as references outside your compiled code.
  • Information on what external libraries, symbols or code snippets the compiled code uses.

By knowing these two pieces of information, the compiler can both safely rename public/global properties and variables as well as completely eliminate code that is never used.

Moving to ADVANCED_OPTIMIZATIONS can be a lot of work, but it can also produce large payoffs in code size and performance. Tips to help the process along:

  • Read and understand the What to watch out for section of the official documentation.
  • Check out the FAQ in the compiler project for tips on debugging compiled code
  • Use warning_level=VERBOSE. While it does produce more warnings, it helps identify things like missing properties which are often the culprit in broken code.
  • Ask lots of questions
Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
0

You can use the java api to tune the compilers optimizations. Basically you customize the command line:
http://blog.bolinfest.com/2009/11/calling-closure-compiler-from-java.html

Alternately, you can create a custom build of the compiler and twiddle with the options used for advanced mode:

see: applyFullCompilationOptions

in: CompilationLevel.java

http://closure-compiler.googlecode.com/git-history/805436ff85a6975fb482aa298c8f3bce4a2a832f/src/com/google/javascript/jscomp/CompilationLevel.java

John
  • 5,443
  • 15
  • 21