PDA

View Full Version : Cache JavaScript and CSS over HTTPS



dmarley
Sep 7th, 2010, 09:58 AM
We run our application over HTTPS and we notice that the Grails Framework adds cache header properties to prevent caching over HTTPS.

Q: How do I stop or override the default behavior of Grails and prevent these header properties from being added to my pages? We see "Cache-Control" set to "no-cache" and other header properties like expiry of the cache-control to some date in the past...

We have been able to get the results we want, but only if we use the render("<p>...</p>") method in our controller and use the response.setHeader("Cache-Control", "public")...

BUT...When we use the convention MVC approach with using .gsp pages for the view it keeps the header properties even though we have used the response.setHeader("...") method.

Any help would be appreciated...

Note: we are not interested in using any plugins at this point in the project...

pledbrook
Sep 8th, 2010, 03:22 AM
Please raise a JIRA issue (http://jira.codehaus.org/browse/GRAILS) for this. I've had a look at the Grails code, but I can't find anything that sets the Cache-Control header. It may be something that Spring MVC is doing.

In the meantime, you could try an 'afterView' filter to clear or change the value of the header:



class MyFilters {
def filters = {
all(uri: "/**") {
afterView = {
if (!response.committed) {
response.setHeader("Cache-Control", ...)
}
}
}
}
}

I don't know whether it will work, but it's worth a try.

vinay076
Mar 18th, 2011, 01:16 PM
Here is the solution
http://stackoverflow.com/questions/1362930/how-do-you-set-cache-headers-in-spring-mvc