最小化 304 请求的麻烦
现在我正在努力减少对我网站的 304 请求。我已经实施了此处要求的建议:
但是,无论我做什么,有些图像都拒绝从缓存中提取,即使它们与提取的其他图像类似。现在我们使用IIS 7.5和chrome来查看网络流量。
以下是图像 btn-blue.png 的初始响应示例,它将从缓存中提取:
Accept-Ranges:bytes
Content-Length:49585
Content-Type:image/png
Date:Fri, 27 Jan 2012 16:02:26 GMT
ETag:"26cb96cdccc1:0"
Expires:Sat, 31 Dec 2012 00:00:00 GMT
Last-Modified:Thu, 26 Jan 2012 20:49:46 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
以下是图像 topnav-blue-poweredbyipipeline.png 的响应标头示例,它将永远不会从缓存中提取缓存:
Accept-Ranges:bytes
Content-Length:2680
Content-Type:image/png
Date:Fri, 27 Jan 2012 16:02:17 GMT
ETag:"b85767a6cdccc1:0"
Expires:Sat, 31 Dec 2012 00:00:00 GMT
Last-Modified:Thu, 26 Jan 2012 20:49:47 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
知道为什么一个会拉而另一个不会吗?
Right now I am trying to minimize the 304 requests to my website. I have implemented the suggestions called for here:
Asking browsers to cache as aggressively as possible
However no matter what I do some images refuse to be pulled from the cache even though they are similar to other ones that are pulled. Right now we are using IIS 7.5 and chrome to view the network traffic.
Here is an example of the initial response for the image, btn-blue.png, that will pull from the cache:
Accept-Ranges:bytes
Content-Length:49585
Content-Type:image/png
Date:Fri, 27 Jan 2012 16:02:26 GMT
ETag:"26cb96cdccc1:0"
Expires:Sat, 31 Dec 2012 00:00:00 GMT
Last-Modified:Thu, 26 Jan 2012 20:49:46 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
Here is an example of the response header for the image, topnav-blue-poweredbyipipeline.png, that will never pull from the cache:
Accept-Ranges:bytes
Content-Length:2680
Content-Type:image/png
Date:Fri, 27 Jan 2012 16:02:17 GMT
ETag:"b85767a6cdccc1:0"
Expires:Sat, 31 Dec 2012 00:00:00 GMT
Last-Modified:Thu, 26 Jan 2012 20:49:47 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
Any idea why one would pull and the other one won't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我们弄清楚了为什么会发生这种情况。事实证明,如果您使用 Enter 按钮导航到网页,Chrome 会积极使用其缓存。如果您使用刷新按钮,Chrome 将会调用几乎每个元素。
So we figured out why this was happening. It turns out if you use the Enter button to navigate to a web page Chrome will aggressively use its cache. If you use the refresh button Chrome will make a call out for almost every element.
您链接的另一篇文章中的所有内容都有一个 Cache-Control: max-age= 标头。你尝试过吗?我不认为过期和 etag 就足够了,我认为你还需要 Cache-Control,但我还没有实际测试过它。
Everything in that other post that you linked has a Cache-Control: max-age= header. Have you tried that? I don't think expires and etag is enough, I think you need the Cache-Control also, but I haven't actually tested it.