18 June 2009 1 Comment

Using GIT with Grails UI-Performance Plugin

I’ve been doing a serious amount of Grails Development lately and if there’s one Grails Plugin I consider mandatory for any serious production deployment then it is the UI-Performance plugin by Burt Beckwith. One of the features of the plugin that reduces server load is versioning and far-future “Expires” and “Cache-Control” headers for static resources.

Each time you generate a new WAR for deployment, a new version is applied to all image, .js, and .css files so files can be cached forever. The next time you deploy a new version of your application, all of the resource file names will have changed, so only then will files be requested. The default process for determining the version is to look at the version of the root project folder in the Subversion metadata files. Since I’ve switched to GIT for all my projects a while ago the plugin would fallback to “System.currentTimeMillis().toString()” to compute the version.

My solution is to include the following line in my projects Config.groovy:

?View Code GROOVY
uiperformance.determineVersion = { -> "git rev-list --max-count=1 HEAD".execute().text.trim() }

This allows the HEAD commit SHA1 hash of the current branch to be used as the uiperformance version for deployment.

One Response to “Using GIT with Grails UI-Performance Plugin”

  1. Jakob 11 November 2009 at 10:29 am #

    Works like a charm, thanks for the share! :)


Leave a Reply