Web Minifier Maven Plugin

Increase the speed of your application download by up to 3 times

Overview

This plugin provides JavaScript minification for Maven projects. It produces a minified version of your JavaScript resources which can be used to construct a minified final artefact. It is designed to be flexible in the way it operates to allow for easy minified resource re-use across your project.

Under the hood, it currently uses the YUI Compressor and Closure Compiler but has a layer of abstraction around these tools which allows for other tools to be used.

Default Behaviour

The default behaviour of the plugin is like so:

  • Copy target/classes to /target/min/classes
  • For each HTML file in /target/min/classes
    • Find all JavaScript script references
    • Join all the referenced JavaScript files together into a new JavaScript file in the same order as the original references
    • Minify the merged JavaScript file
    • Replace the script references in the HTML file with a reference to the merged, minified script

Minified Resource Grouping with Split Points

The plugin also supports more configurable behaviour; you can give it any number of JavaScript file names which are to be used as 'split points'; if a split point is reached when collating the list of resources within a HTML file then resources up to and including that point are merged into a single file, and a new merged file begins at the following resource, if it exists.

For example, if a HTML file contains the following script references:

  • a.js
  • b.js
  • c.js
  • d.js
  • e.js

By default, these would all be merged into a new file 1.js and your HTML script references replaced by a single one, like:

  • 1.min.js (containing a.js, b.js, c.js, d.js and e.js)

If you configured a JavaScript split point of 'c.js', the HTML file could then contain the following script references:

  • 1.min.js (containing a.js, b.js and c.js)
  • 2.min.js (containing d.js and e.js)