YUI Minify Resources

  • Tags: deprecated
  • Latest: 0.1.5
  • Last Updated: 06 March 2012
  • Grails version: 1.2 > *
0 vote

5% of Grails users

Dependency:
runtime ":yui-minify-resources:0.1.5"

 Documentation  Source

Summary

Minifies static css and js resources using the YUI Compressor library

Description

Unfortunately I have no time to properly maintain this plugin anymore. If you're interested in taking over maintenance, please ping me at info (at) block-consult.com so that we can arrange the handover.

This plugin leverages the resources plugin to apply Minification to Javascript and CSS static resources using YUI Compressor. It works well together with cached-resources plugin and zipped-resources plugin.

By default all files handled by resources plugin that end with .css or .js are minified. All other resources - including resources ending with .min.css and .min.js - are ignored.

Due to an upstream bug in yui compressor's maven packages, the yui compressor jar file is shipped as part of the plugin itself. This jar (partially) includes Mozilla Rhino classes, which may lead to strange javascript compilation errors in projects that depend on rhino packages as well (e.g. coffeescript resources plugin).

Usage

Just install the plugin and then start your application. There's no mandatory configuration required.

grails install-plugin yui-minify-resources

All css and js resources are converted into minified versions. They are also renamed to min.css and min.js respectively. Note: Your original css and js files remain untouched.

See the documentation for the resources plugin to learn how to define and use resources.

Optional configuration

The following customizations are available:

1. Customize file inclusion and exclusion patterns

Config.groovy:
grails.resources.mappers.yuicssminify.includes = ['**/*.css']
grails.resources.mappers.yuijsminify.includes = ['**/*.js']
grails.resources.mappers.yuicssminify.excludes = ['**/*.min.css']
grails.resources.mappers.yuijsminify.excludes = ['**/*.min.js']

2. Exclude specific resource files from minification

MyCustomResources.groovy:
"myModule" {
   resource url: [dir: "js", file: "myResourceThatShouldRemainUntouched.js"],  exclude:'yuijsminify' 
}

the above is the preferred way to specify a specific minification exclusion. But for compatibility reasons, this also works:

"myModule" {
   resource url: [dir: "js", file: "myResourceThatShouldRemainUntouched.js"],  nominify: true
}

3. Custom minification strategies

See YUI Compressor documentation for further details:

Config.groovy:

//Completely disable css and/or js processor
grails.resources.mappers.yuicssminify.disable=true
grails.resources.mappers.yuijsminify.disable=true

//Insert a line break after the specified column number grails.resources.mappers.yuijsminify.lineBreak = <column_number> grails.resources.mappers.yuicssminify.lineBreak = <column_number>

//Read the input file using <charset> grails.resources.mappers.yuijsminify.charset = <charset> grails.resources.mappers.yuicssminify.charset = <charset>

//The following options apply to YUI JS Minifier only

//Minify only, do not obfuscate javascript code grails.resources.mappers.yuijsminify.js.noMunge = [true|false]

//Preserve all semicolons in javascript files grails.resources.mappers.yuijsminify.js.preserveAllSemicolons = [true|false]

//Disable all micro optimizations in javascript files grails.resources.mappers.yuijsminify.js.disableOptimizations = [true|false]

License

The plugin is licensed under Apache 2 license, see http://www.apache.org/licenses/LICENSE-2.0 The YUI Compressor library used to compress the resources is licensed under BSD license, see http://developer.yahoo.com/yui/license.html

History

  • August 10, 2011: Version 0.1 - Initial release: Migrated from minify-resources
  • September 23, 2011: Version 0.1.1 - Bug Fix release
  • September 26, 2011: Version 0.1.2 - Bug Fix release (bring back 'disable' option for resource mappers)
  • November 10, 2011: Version 0.1.3 - Declare YUI Compressor lib as BuildConfig dependency
  • November 10, 2011: Version 0.1.4 - Back to YUI Compressor as local lib. See upstream bug report for details
  • March 07, 2012: Version 0.1.5 - Upgrade to YUI Compressor 2.4.7 (still as local lib)