Description
Adam Skogman opened SPR-12562 and commented
When using:
<mvc:resources mapping="/resources/"
cache-period="31556926">
<mvc:resource-chain resource-cache="true">
mvc:resolvers
mvc:version-resolver
<mvc:content-version-strategy patterns="/" />
</mvc:version-resolver>
</mvc:resolvers>
</mvc:resource-chain>
</mvc:resources>
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);
SUGGESTION:
Add a config option to mvc:resources:
<mvc:resources mapping="/resources/**"
cache-period="31556926" must-revalidate="false">
...
</mvc:resources>
Affects: 4.1.3
Issue Links:
- Server-side HTTP caching improvements [SPR-11792] #16413 Server-side HTTP caching improvements
2 votes, 4 watchers