Tauren
Tauren

Reputation: 27235

Maven plugin for versioning and minifying javascript

Single Page Javascript Application

I have built a sophisticated ajax-driven single page webapp that uses a RESTful backend web service serving JSON. The javascript is split into many different files, each file representing some sort of feature or component.

While the service has been in alpha testing, I've just be serving all these files separately without minification. But now that I'd like to launch a beta version, I really need to combine files, minify them, and version them. I want to add this to my build process, using Maven.

Javascript File Types

I'm using the following "types" of javascript files, of which #3 and #4 are my concerns:

  1. External files, such a jquery and jquery-ui served from the Google CDN. Rarely change these versions, can be handled manually.
  2. Jquery plugins that I'm hosting myself, such as fullcalendar or ui-layout. Again, I rarely update these to new versions and can handle it manually.
  3. Application-wide javascript code. Custom javascript that is spread across many files and can change occasionally. All of these files need to be loaded for the app to work.
  4. Feature-specific javascript code. Custom javascript that is loaded on demand when a specific feature is requested. This code can change quite frequently and is not loaded at startup.

Build Objectives

I'd like to do the following during my build process:

Questions

Upvotes: 51

Views: 24210

Answers (3)

Chris Dolan
Chris Dolan

Reputation: 8963

Here's a brand-new Maven plugin that targets this task: http://mojo.codehaus.org/webminifier-maven-plugin/

Upvotes: 11

Ateş Göral
Ateş Göral

Reputation: 140050

I've successfully incorporated RequireJS optimization (uses Google Closure compiler + does concatenation) in a Maven environment (for single page JS app). See my question and the follow up answer for details: RequireJS Compilation in Maven project with external JS dependencies

You could probably expand on that to version and archive the minified JS artifacts.

Upvotes: 3

Taylor Leese
Taylor Leese

Reputation: 52310

Take a look at the yuicompressor-maven-plugin. It can aggregate various js (as well as css) files as well as minify and obfuscate them.

Upvotes: 22

Related Questions