Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

JavaScript minification

Chuck Dumont edited this page Apr 27, 2016 · 15 revisions

The Aggregator uses the Google Closure Compiler to perform JavaScript minification of .js modules, including:

  • Removal of comments, white-space and unneeded block delimiters
  • Renaming of local and function variables to use shorter names
  • Dead code removal
  • Code re-organization (e.g. changing if-then-else blocks to use tertiary operator).

The Aggregator uses the Closure Compiler's simple optimization level for JavaScript optimizations. You can optionally specify an optimization level of whitespace only for debugging by setting optimize='whitespace' in the loader extension config. This will cause the compiler to remove comments and whitespace, but not rename any variables. Setting optimize='none' removes all optimization, by-passing the compiler, but on versions prior to 1.2 this has the effect of disabling code trimming using has.js feature detection, as well as require list expansion, since both of these features depend on functionality provided by the compiler. In versions 1.2 and above, using an optimization level of none does not restrict the use of any other features.

See the sample application's test.html and loaderConfig.js for example code showing how to set loader extension config properties from URL query args specified on the application page's URL.

Starting with version 1.3.3, the use of source maps for JavaScript code is supported though the sourcemaps loader extension config parameter and the sourceMaps option. When source maps are enabled, each layer will specify the URL of a source map for the layer. The URL for a layer source map is the same as the URL for the layer, except that /_sourcemap is appended to the resource path.

Starting with version 1.3.7, arbitrary Closure Compiler options may be specified using the compilerOptions Server-side AMD Config property.