Caching Http缓存-检查文件更改适用于html,但不适用于xml-Chrome

Caching Http缓存-检查文件更改适用于html,但不适用于xml-Chrome,caching,http-headers,http-caching,Caching,Http Headers,Http Caching,我有两个文件,我想缓存客户端,直到原点改变 对html页面(index.html)的调用在响应中具有以下标题: 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"

我有两个文件,我想缓存客户端,直到原点改变

对html页面(index.html)的调用在响应中具有以下标题:

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
HTTP/1.1 200 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
对xml页面(application context dashboard.xml)的调用在响应中具有以下标题:

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
HTTP/1.1 200 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
现在,当我重新加载它们时,对于index.html,会发送一个304来检查文件是否已更改。对于xml文件,发送no 304,并触发客户端缓存

304调用index.html: 请求:

有没有办法为xml文件获得相同的结果?+为什么它适用于html而不适用于xml?初始请求的两个头似乎是相同的

浏览器:Chrome

其他静态内容(如swf、txt等)也存在同样的问题

更新:


显然,Chrome在index.html上做得还不错,但firefox就不行了……

当你重新加载页面时,浏览器必须检查它是否仍然是最新的。因此,它将再次请求该页面。If None匹配和If Modified Since请求头允许服务器返回304 Not Modified响应

对于页面上的其他元素,它会按应有的方式执行缓存。您的第一个响应包含缓存控件:public,max age=7776000标头。这样,您可以告诉浏览器在接下来的三个月内不要检查此文件如果您想让浏览器反复请求每个文件,请删除“最长使用期限”部分并添加“必须重新验证”。ETag仍允许您发送304s


您将在中找到更详细的解释。

Thx。要在asp.NET中完成此操作,您需要在system.webserver-->clientcache-->cacheControlCustom=“public”下添加staticcontent标记,必须重新验证。所有静态内容都将具有额外的标题。