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

ResourceHttpRequestHandler serves all files with must-revalidate cache header, should not do that when using a content versioning strategy [SPR-12562] #16988

spring-issuemaster opened this issue Dec 19, 2014 · 1 comment


None yet
2 participants
Copy link

commented Dec 19, 2014

Adam Skogman opened SPR-12562 and commented

When using:
<mvc:resources mapping="/resources/"
<mvc:resource-chain resource-cache="true">
<mvc:content-version-strategy patterns="/
" />

The point is to server the resources once and only one per URL. The resources do not ned to be checked, if in the browser cache.

However, the default behaviour of the ResourceHttpRequestHandler is to add a must-revalidate to the Cache-Control header. This adds an un-necessary round-trip for every resource. On a single page, this can be something like 50+ unnecessary HTTP roundtrips.

The bug is in ResourceHttpRequestHandler#handleRequest:

line 250: checkAndPrepare(request, response, true);

That hardcoded "true" causes (some ways down the call-stack) WebContentGenerator#cacheForSeconds to apply the header (argument is "mustRevalidate"):

String headerValue = "max-age=" + seconds;
if (mustRevalidate || this.alwaysMustRevalidate) {
     headerValue += ", must-revalidate";
response.setHeader(HEADER_CACHE_CONTROL, headerValue);

Add a config option to mvc:resources:

<mvc:resources mapping="/resources/**"
    cache-period="31556926" must-revalidate="false">


Affects: 4.1.3

Issue Links:

  • #16413 Server-side HTTP caching improvements

2 votes, 4 watchers


This comment has been minimized.

Copy link
Collaborator Author

commented Mar 23, 2015

Brian Clozel commented

As of 4.2, ResourceHttpRequestHandlers don't serve resources with a "Cache-Control: must-revalidate" header.

Also, #16413 (and sub-tasks) allow to configure flexible strategies for HTTP caching like this:

public void addResourceHandlers(ResourceHandlerRegistry registry) {
  CacheControl cc = CacheControl.maxAge(365, TimeUnit.DAYS).noTransform();  

This will add a "Cache-Control: max-age=31536000, no-transform" response header when serving resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.