Http caching - check for file change works with html but not with xml - Chrome
I have two files which I would like to cache client side untill the origin changes.
The call to the html page (index.html) has following headers in the response:
HTTP/1.1 200 OK
Cache-Control: public,max-age=7776000
Content-Type: text/plain
Content-Encoding: gzip
Last-Modified: Wed, 13 Jul 2011 13:02:04 GMT
Accept-Ranges: bytes
ETag: "e07f1e105d41cc1:0"
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 03 Aug 2011 11:47:47 GMT
Content-Length: 242
The call to the xml page (application-context-dashboard.xml) has following headers in the response:
HTTP/1.1 2开发者_运维百科00 OK
Cache-Control: public,max-age=7776000
Content-Type: text/xml
Content-Encoding: gzip
Last-Modified: Wed, 03 Aug 2011 11:31:56 GMT
Accept-Ranges: bytes
ETag: "10ba5f3d051cc1:0"
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 03 Aug 2011 11:47:14 GMT
Content-Length: 457
Now, when I reload them, for the index.html, a 304 is sent to check whether the file has changed. For the xml file no 304 is sent and client cache is triggered.
304 call for index.html: Request:
GET /edumatic3/trunk/backend/index.html HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: nl,en-US;q=0.8,en;q=0.6,fr;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: CurrenUICulture=en-us
If-None-Match: "e8626a973e45cc1:0"
If-Modified-Since: Mon, 18 Jul 2011 11:34:01 GMT
Is there a way to achieve the same result for the xml file? + Why does it work for html and not for xml? The two headers for the initial request seem to be identical.
Browser: Chrome.
Same problem for other static content like swf, txt, ...
UPDATE:
Apparently Chrome does an OK job for the index.html, but firefox for instance does not...
When you reload a page the browser must check if it is still up to date. So it will request the page again. The If-None-Match and If-Modified-Since request headers allow your server to return a 304 Not Modified response.
For the other elements on the page it performs caching as it should. Your first response contained the Cache-Control: public,max-age=7776000 header. This way you tell the browser not to check this file for the next three months. Remove the max-age part and add must-revalidate if you want the browser to request every file over and over. The ETag will still allow you to send 304s.
You will find a more detailed explanation in RFC 2616, Section 14.9.4 Cache Revalidation and Reload Controls.
精彩评论