Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails 3.2.4: Http header "Cache-Control:no-store" on static resources causes slow response and high http traffic #10410

Closed
3 of 4 tasks
atasc opened this issue Jan 17, 2017 · 5 comments

Comments

@atasc
Copy link

atasc commented Jan 17, 2017

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Full description

All static resources located in src/main/webapp are served with Http header "Cache-Control:no-store",
this causes a slow response and a high http traffic as the browser does not use cache and downloads these resources every time.
I've tried to set the header (response.setHeader('Cache-Control', 'max-age=600')) using an Interceptor or a Filter with no luck,
it is set to 'no-store' later in the response chain.

Is it possible to change this behaviour?

Steps to Reproduce

  1. create an empty 3.2.4 app
  2. add some static resource to src/main/webapp for example src/main/webapp/css/style.css
  3. run-app
  4. Open http://localhost:8080/static/css/style.css
  5. Check the Http response header

Expected Behaviour

Actual Behaviour

All static resources are served with Http header "Cache-Control:no-store"

Environment Information

  • **Operating System: Linux 64 bit
  • **Grails Version: 3.2.4
  • **JDK Version: 1.8.0_111
  • **Container Version: Tomcat 8

Example Application

myapp.zip

@graemerocher
Copy link
Member

You can configure grails.resources.cachePeriod and set it to whatever you want in application.yml

@pangeaos
Copy link

pangeaos commented May 4, 2017

Is there any documentation? It's hard to find it.
grails: resources: cachePeriod: 120
It's not working for me.

image

@abobwhite
Copy link

This solution DOES work but how can we avoid this on certain file types? I have an SPA with an index.html that I absolutely do not want cached but I want everything else cached until eternity because new builds have new file names for everything but index.html

@ginchauspe
Copy link

On 3.3.9 add grails.resources.cachePeriod=number in your application.groovy

@erichelgeson
Copy link
Contributor

I was a bit curious about this so dug in a bit - as a work around you can add your own no-cache ResourceHandler for index.html and then have the static resources use the cachePeriod - Though I think it'd be worth while to add this in as an option in grails as SPA's being used more often.

@Configuration
class SpaResolverConfig implements WebMvcConfigurer {
    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = ["classpath:/public/"]
    
    @Override
    void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler('/static/index.htm*') // needs to be an antmatcher
                .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS)
                .setCachePeriod(0)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants