Resources

46 votes

82% of Grails users

Dependency:
runtime ":resources:1.2.13"

 Documentation  Source  Issues

Summary

HTML resource management enhancements to replace g.resource etc.

Description

To use the plugin, add this to your BuildConfig.groovy:

plugins {
   runtime ':resources:1.2.13'
}

Be sure to use the most recent release; due to a bug, this page may not show the most current release but it is currently 1.2.13

since 1.2.13 resources are looked up using servletContext.getResource method by default. To enable using the grailsResourceLocator bean, you must set this setting in Config.groovy

// enable only when you need it
grails.resources.resourceLocatorEnabled = true
This setting might be needed in exceptional cases where resources should be resolved from binary plugins.

If you have problems serving resources with 1.2.13 update, please check your grails.resources.adhoc.patterns and grails.resources.adhoc.includes settings in Config.groovy

// What URL patterns should be processed by the resources plugin
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']
grails.resources.adhoc.includes = ['/images/**', '/css/**', '/js/**', '/plugins/**']

Since version 1.2.13 uses servletContext.getResource for default for uri-to-url resolution, it adds a new cache setting to Config.groovy:

// uri-to-url resolution cache timeout in milliseconds
// 0 == caching disabled , -1 == no timeout
grails.resources.uriToUrlCacheTimeout = 30000

This plugin represents a new way of declaring and linking to static resources in your application and plugins. Resource dependencies can be declared (e.g. jQuery UI requires jQuery) and pages simply indicate which resource modules they require. The plugin does the rest, and provides a processing pipeline for advanced optimisations. There is a screencast by Bobby Warner which demonstrate the usage of Spring Security Core plugin and Resources plugins as well as some unit testing.

Full documentation

See also the resource mapping plugins: