You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow must-revalidate to be suppressed in ResourceHttpRequestHandler [SPR-10464] #15097
It's worth noting that the property alone will not do the job. I've just tried the following, but ResourceHttpRequestHandler calls checkAndPrepare with lastModified=true, but this then gets turned into a call of applyCacheSeconds(..., mustRevalidate=true).
To make it work, I have to override ResourceHttpRequestHandler.setHeaders() and set Cache-Control manually, and override handleRequest() to duplicate but without the If-Modified-Since logic, so that browser doesn't get a Last-Modified header
If I understand correcly, you want browsers to cache those resources but you don't want them to revalidate them with GET requests/304 responses, I assume for front-end performance reasons.
I was wondering if you considered setUseExpiresHeader(true) and setUseCacheControlHeader(false) - in that case, client would only try to fetch resources if URLs changed (no GET/304). Could you tell me a little bit more about your use case?
It is for a cache busting implementation. I no longer have access to the client issue tracker as to the reasoning, as it was a good while ago. We needed the headers as specified, but I don't recall the detail of what the issues were. It is possibly due to having Apache in front of the server, or CDN related issues.
I see, so it's got nothing to do with 304/Last-modified etc.
In that case, removing "must-revalidate" from the Cache-Control header authorizes proxy-caches (such as Apache, Varnish, CDNs) to serve stale resources for a while without hitting the origin server.
You can also take a look at #11789 and #13194 - those may interest you.
Looking at the other two, I'd say that what would be useful is for ResourceHandlerRegistration to capture the intent in a readable manner, and warn or error on invalid/unlogical combinations of these.
Perhaps it might be worth investigating how some of these requirements play out via the more opinionated world of Spring Boot. For example, Spring Boot might provide public/private based on part of the path (e.g. public/static, secure/static).
It'd be interesting to get views of others, but I suspect 4.1.0.M1 might be a better place to get feedback on changes for these issues now we're closing in on GA for 4.0...
Support for this would be helpful for me as well. (In my case, the cache is CloudFlare, which will serve an offline static copy of your site if Something Bad happens, but the HTTP spec says that must-validate requires expiration on schedule.)
Activity
spring-projects-issues commentedon Apr 16, 2013
Neale Upstone commented
Rossen:
It's worth noting that the property alone will not do the job. I've just tried the following, but ResourceHttpRequestHandler calls checkAndPrepare with lastModified=true, but this then gets turned into a call of applyCacheSeconds(..., mustRevalidate=true).
To make it work, I have to override ResourceHttpRequestHandler.setHeaders() and set Cache-Control manually, and override handleRequest() to duplicate but without the If-Modified-Since logic, so that browser doesn't get a Last-Modified header
spring-projects-issues commentedon Oct 1, 2013
Konrad Garus commented
How about this:
spring-projects-issues commentedon Oct 2, 2013
Rossen Stoyanchev commented
Sounds like a good idea. Would anyone have time to put together a pull request?
spring-projects-issues commentedon Nov 8, 2013
Brian Clozel commented
Hi Neale Upstone,
If I understand correcly, you want browsers to cache those resources but you don't want them to revalidate them with GET requests/304 responses, I assume for front-end performance reasons.
I was wondering if you considered
setUseExpiresHeader(true)andsetUseCacheControlHeader(false)- in that case, client would only try to fetch resources if URLs changed (no GET/304). Could you tell me a little bit more about your use case?Thanks!
spring-projects-issues commentedon Nov 11, 2013
Neale Upstone commented
Hi,
It is for a cache busting implementation. I no longer have access to the client issue tracker as to the reasoning, as it was a good while ago. We needed the headers as specified, but I don't recall the detail of what the issues were. It is possibly due to having Apache in front of the server, or CDN related issues.
spring-projects-issues commentedon Nov 12, 2013
Brian Clozel commented
I see, so it's got nothing to do with 304/Last-modified etc.
In that case, removing "must-revalidate" from the
Cache-Controlheader authorizes proxy-caches (such as Apache, Varnish, CDNs) to serve stale resources for a while without hitting the origin server.You can also take a look at #11789 and #13194 - those may interest you.
spring-projects-issues commentedon Nov 12, 2013
Neale Upstone commented
Yes. That's the scenario.
Looking at the other two, I'd say that what would be useful is for
ResourceHandlerRegistrationto capture the intent in a readable manner, and warn or error on invalid/unlogical combinations of these.Perhaps it might be worth investigating how some of these requirements play out via the more opinionated world of Spring Boot. For example, Spring Boot might provide public/private based on part of the path (e.g. public/static, secure/static).
It'd be interesting to get views of others, but I suspect 4.1.0.M1 might be a better place to get feedback on changes for these issues now we're closing in on GA for 4.0...
spring-projects-issues commentedon Nov 12, 2013
Brian Clozel commented
Thanks for your feedback Neale Upstone.
I'll move this issue to the backlog and we will fix it along the other issues.
I'll definitely ping you then to get your feedback.
spring-projects-issues commentedon Jan 17, 2014
Christopher Smith commented
Support for this would be helpful for me as well. (In my case, the cache is CloudFlare, which will serve an offline static copy of your site if Something Bad happens, but the HTTP spec says that
must-validaterequires expiration on schedule.)spring-projects-issues commentedon Mar 23, 2015
Brian Clozel commented
As of 4.2, the "must-revalidate" directive is now disabled by default when serving resources with ResourceHttpRequestHandler.
A new
CacheControlAPI allows new custom configurations for the "Cache-Control" HTTP response header: