当同时提供 max-age 和 Last-Modified 标头时,Webkit 不缓存 [英] Webkit not caching when both max-age and Last-Modified headers are provide

查看:38
本文介绍了当同时提供 max-age 和 Last-Modified 标头时,Webkit 不缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个带有自定义 Web 服务器的基于 Web 的应用程序,但我遇到了 webkit 浏览器无法缓存图像、样式表和 javascript 的问题.

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.

我已经追踪到 Cache-Control: max-age 和 Last-Modified 之间的某种关系.如果两者都被指定,那么 webkit 似乎会忽略 max-age 标头,并在每次使用资源时检查文件是否已被修改.该网站在第一页上有一个 iframe,它会导致样式表等在一秒钟内被请求两次!

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!

如果您删除 Last-Modified,那么直到第二天才会重新请求文件;但是第二天的请求将不再是 if-modified-since 请求,要求服务器重新发送所有内容,而不仅仅是 304 标头.

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.

在 IE9、Firefox 10.0 和 Opera 11.61 上,浏览器会正确缓存并且不会重新请求图像,只会重新请求具有 Cache-Control: no-cache 标头属性的 HTML.

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.

在 Chrome 16.0.912.77 m 和 Safari 5.1.2 (7534.52.7) 上,每次都会对每个页面上的每个图像发出条件请求.服务器以 304 标头响应,同样包含 max-age 属性,但它们都继续请求.

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.

我与响应一起发送的示例 HTTP 标头是:

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?

所有浏览器都在 Win7 Pro x64 上运行,上面的 HTTP 标头是 Fiddler 的原始输出,所以这正是浏览器接收的内容.

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.

谢谢

莫格

推荐答案

我遇到了同样的问题,但不是 Webkit 范围的;Safari 和 Chrome 在隐身模式下工作正常.我尝试禁用所有没有区别的扩展,但清除整个缓存似乎已修复它.

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.

我的猜测是,如果您第一次将 Cache-Control 标头添加到您的网站,那么 Chrome 不会正确覆盖其缓存中的旧标头.这会给现有用户正确使用新的缓存设置带来一些问题.

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.

这篇关于当同时提供 max-age 和 Last-Modified 标头时,Webkit 不缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆