问题
I have a writing a web based application with a custom web server and I'm having problems with the webkit browsers not caching images, stylesheets and javascript.
I have tracked it down to some relationship between Cache-Control: max-age and Last-Modified. If both are specified then webkit seems to ignore the max-age header and check if the file has been modified EVERY time the resource is used. The site has an iframe on the first page and it results in stylesheets, etc. being requested twice within a second!
If you remove the Last-Modified then the files will not be re-requested until the next day; however the requests the next day will no longer be if-modified-since requests, requiring the server to resend everything instead of just a 304 header.
On IE9, Firefox 10.0 and Opera 11.61 the browsers cache correctly and don't re-request the images, only the HTML, which has a Cache-Control: no-cache header attribute.
On Chrome 16.0.912.77 m and Safari 5.1.2 (7534.52.7) a conditional request is made for every image on every page, every time. The server responds with a 304 header, again containing the max-age attribute but they both keep requesting.
An example HTTP header I'm sending with a response is:
HTTP/1.1 200 OK
Date: Mon, 06 Feb 2012 15:12:12 GMT
Cache-Control: max-age=86400
Content-length: 708
Content-type: image/gif
Last-Modified: Fri, 6 Jan 2012 14:39:07 GMT
Server: Webspring
Does anyone have any suggestions of how I can get these browsers to all respect my cache headers?
All the browsers are running on Win7 Pro x64 and the HTTP header above is the raw output of Fiddler, so that is exactly what the browser is receiving.
Note: I had asked a previous question before I discovered this was an interaction between header fields. I have deleted the previous question as it was no longer accurate.
Thanks
Mog
回答1:
I was having the same problem but it wasn't Webkit wide; Safari and Chrome in incognito work fine. I tried disabling all extensions which made no difference but clearing the entire cache seemed to have fixed it.
My guess is that if you add the Cache-Control header to your site for the first time then Chrome doesn't correctly overwrite the old headers in its cache. This poses some problems with getting existing users over to your new cache settings properly.
来源:https://stackoverflow.com/questions/9176874/webkit-not-caching-when-both-max-age-and-last-modified-headers-are-provide