我正在使用 PHP 生成动态内容。
我正在发送以下 HTTP header :
HTTP/1.1 304 Not Modified
Date: Sun, 09 Dec 2012 17:24:41 GMT
Server: Apache
Connection: keep-alive, Keep-Alive
Keep-Alive: timeout=1, max=100
Etag: "237f43b800e655dbe6567f7d32d34c99"
Expires: Sun, 16 Dec 2012 17:24:41 GMT
Cache-Control: max-age=604800
Vary: Accept-Encoding
稍后我会检查 Etag 是否发送 header('HTTP/1.1 304 Not Modified')
(如果匹配)。
这与 Chrome 和 Firefox 完美配合。
但是,Safari(版本 6.0.2)不会发送“If-Modified-Since”和“If-None-Match” header 。
这是 Safari 在第二页点击时发送的请求 header :
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cache-Control: max-age=0
该页面上链接的所有其他文件都会收到正确的请求 header ,并且 Safari 在适当的情况下使用缓存文件或 304。
为什么不向 Safari 发送正确的请求 header ? 我可以改变什么?
谢谢!
最佳答案
如果-修改-自
If-Modified-Since的笔记警告不要使用与 Last-Modified
响应 header 内容不同的内容:
Note: If a client uses an arbitrary date in the If-Modified-Since header instead of a date taken from the Last-Modified header for the same request, the client should be aware of the fact that this date is interpreted in the server's understanding of time.
您的回复不包含 Last-Modified ,但即使确实如此,规范中也没有任何内容表明用户代理必须或应该发送 If-Modified-Since,他们只是可以。
如果-无-匹配
至于为什么 Safari 不发送 If-None-Match打败我;你的ETag看起来有效。
一般情况下强制执行缓存
一般来说,规范中没有任何内容表明您必须缓存,只是当您这样做时,您必须遵守 Cache-Control 。所以这是一种不对称的关系,您可以强制(透明)缓存与源服务器重新检查,但作为源服务器,您不能强制用户代理进行缓存。
我能做什么?
Safari 仅 partly免费软件。因此,如果添加 Last-Modified 没有帮助,那就没什么了。
关于php - Safari 不发送 "If-Modified-Since"和 "If-None-Match" header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13789855/