Question

We work on a web application in Grails 2.3.5.

It comprises of web service with REST API. Web UI is developed in ExtJS and packaged into Grails war file (in web-app).

Web UI is bootstraped by loading a static index.html that loads css, js files and other resources as needed.

Static resources are configured in Config.groovy:

grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*', '/spa/*', '/hds/*']

Static content is not properly cached in the browser.

I'd like to configure Grails to cache static files if they are not updated on the server and force updating them when they are changed.

The files on the server were today (2014-05-15).

Example request

GET /hdspro/static/hds/resources/js/versionInfo/versionInfo.js HTTP/1.1
Host: dev.healthdataspace.de
Connection: keep-alive
Cache-Control: max-age=0
Accept: */*
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36
Referer: https://dev.healthdataspace.de/hdspro/static/hds/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: sl,en-GB;q=0.8,en;q=0.6,de;q=0.4,en-US;q=0.2
Cookie: JSESSIONID=34C496D289B9CE68F31AE2AFD5031CB2
If-Modified-Since: Thu, 15 May 2014 13:00:42 GMT

Response:

HTTP/1.1 200 OK
Server: nginx/1.6.0
Date: Thu, 15 May 2014 14:15:29 GMT
Content-Type: application/javascript
Content-Length: 130
Connection: keep-alive
Last-Modified: Thu, 15 May 2014 13:00:42 GMT

Even though the file that was cached in the browser is the same as the the one on the server, it was downloaded again.

I tried to use cached-resources plugin to achieve that but without success because all of the files were converted to hashed files and load failed.

Do you have any experience with caching static content in Grails?

Thanks for help.

Was it helpful?

Solution

Id take a look at not using the resources plugin but rather use the the grails asset-pipeline plugin which will become standard in grails 2.4. It handles caching and digesting right off the bat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top