如何让 Safari 发送 if-modified-since 标头?
当我生成一个页面时
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Last-Modified: Mon, 04 Apr 2011 20:08:33 GMT
Vary: Accept-Encoding
Date: Mon, 11 Apr 2011 01:36:21 GMT
Content-Length: 3019
,我会发送标头,当我尝试再次获取此页面时,所有浏览器都会发送正确的请求并获得 304 答案,除了 Safari - 它从不发送 if-modified-since。它总是重新加载整个页面,即使它没有被更改
Safari 的这种行为是否已知以及如何使 Safari 以正确的方式工作?
When I generate a page I send headers
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Last-Modified: Mon, 04 Apr 2011 20:08:33 GMT
Vary: Accept-Encoding
Date: Mon, 11 Apr 2011 01:36:21 GMT
Content-Length: 3019
then, when I try to get this page again all browsers send correct request and get 304 answer except Safari - it never sends if-modified-since. It always reloads whole page even it havnt been changed
Does this behavior of Safari known and what to do to make Safari work in right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Bart Lateur 写了一篇文章 关于这一点,有一段关于 Safari 的说明:
Bart Lateur wrote a post about this, with a paragraph stating about Safari:
我在 Safari 8.0 中遇到了这个问题。尽管向 Safari 提供了 Last-Modified 标头,但它不会在后续请求中提供 If-Modified-Since 标头。我的解决方案是另外将
Expires
标头设置为与Last-Modified
标头相同的 html-date。以下是成功交换的示例:
初始请求
来自 Safari 的标准首次请求。
初始响应
我将
Expires
和Last-Modified
标头指定为相同的有效 html-date。我没有尝试过,但我怀疑 Safari 是否会遵守设置为-1
的Expires
标头。后续请求
最后,Safari 提供了所需的
If-Modified-Since
标头。后续响应
我可以满意地返回 304。
I ran into this with Safari 8.0. Despite providing the
Last-Modified
header to Safari it would not provide theIf-Modified-Since
header on subsequent requests. The fix in my case was to additionally set theExpires
header to the same html-date as theLast-Modified
header.Here's an example of what the successful exchange looks like:
Initial Request
Standard first request from Safari.
Initial Response
I specify both the
Expires
andLast-Modified
headers as the same valid html-date. I have not tried but I doubt Safari will honor anExpires
header set to-1
.Subsequent Request
At last Safari provides the needed
If-Modified-Since
header.Subsequent Response
I can satisfyingly return a 304.
Safari 只是部分免费软件。除了屏住呼吸等待 Apple 将整个 Safari 作为免费软件发布之外,作为 Safari 用户,您还可以使用缓存代理并将其配置为违反规范并忽略 Safari 发送的 Cache-Control 标头。
Squid 有 refresh_pattern 指令,我确信其他代理也有类似的功能。
然后,您可以将 Safari 配置为使用代理,或者您可以本着 颠倒互联网。
Safari is only partly free software. Other than holding your breath until Apple releases the whole of Safari as free software, as a Safari user you could use a caching proxy and configure it to break the spec and ignore the Cache-Control headers Safari sends.
Squid has the refresh_pattern directive, and I'm sure other proxies have similar functionality.
You can then configure Safari to use the proxy, or you can do it transparently in the spirit of upside-down-ternet.
在我的测试中,Safari 需要“Expires”或“Cache-Control”标头以及“Last-Modified”标头。
或者,
注意:Safari 需要“max-age”来尊重“Last-Modified”
In my testing, Safari is expecting either an "Expires" or "Cache-Control" header along with "Last-Modified".
Or,
NOTE: "max-age" was required for Safari to honor the "Last-Modified"