Plugins You can find out about all the publicly available Grails plugins.

Cached Resources

  • Authors: Marc Palmer
7 votes

13% of Grails users

runtime "org.grails.plugins:cached-resources:1.0"

 Documentation  Source  Issues


Provides a "hash and cache" mapper for the resources framework, automatically creating safe unique filenames for your resources and setting them to eternally cache in the browser.


This plugin leverages the Resources plugin to make static resources browser-cacheable with unique filenames based on their content. It works well together with zipped-resources plugin

There is no application versioning required as this plugin uses a similar approach to "git". It hashes files and renames them to their hash. So when your resource file contents change, the file names automatically change - no more problems with stale JS or CSS content in your client browsers.

The result is that even if your application version changes between deployments, if some resources did not change in that release, all your users will still be able to continue using their previous long-term cached file without reloading from your site.

It is zero-hassle static file caching.


Just install:

grails install-plugin cached-resources

See the documentation for the resources plugin for how to define your resources.

Commercial Support

Commercial support is available for this and other Grailsrocks plugins.

Resource mappers

This plugin adds the resource mapper called hashandcache which you can include/exclude based on URIs or individual resources using normal Resources configuration mechanisms.


There are mapper-specific Config values supported:

  • flatten - Controls whether or not the mapper should flatten directories after creating the unique file names
  • shorten - Controls whether or not the mapper should shorten the generated hashed file names using base62 encoding (yes that's 62 not 64).
You set these using standard per-mapper config mechanisms supplied by Resources.


Each file is hashes using SHA-256. Using the resources plugin, it is able to rename the file and change the URL generated when your application links to the resource.

Then, when requests come in, it adds all the required caching headers to attempt "eternal" caching by intermediate caches and the client browser. It does this using the cache-headers plugin.


You may want to control which file types are hashed and cached, or exclude all hashing and caching in the development environment. For details see the configuration documentation for the Resources plugin.