什么是优先:ETag或Last-Modified HTTP标头? [英] What takes precedence: the ETag or Last-Modified HTTP header?

查看:397
本文介绍了什么是优先:ETag或Last-Modified HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于后续两个请求,浏览器会给予以下两个标题中的哪一个更多权重:其中一个更改:ETag或Last-Modified?

For two subsequent requests, which of the following two headers is given more weight by browsers should one of them change: ETag or Last-Modified?

推荐答案

根据 RFC 2616 第13.3.4节,HTTP 1.1客户端必须在任何缓存条件请求中使用ETag,如果同时存在ETag和Last Modified,它应该同时使用两者。除非服务器明确声明弱,否则ETag标头被认为是强验证器(参见第13.3.3节),而Last Modified标头被认为是弱的,除非它与Date标头之间至少存在微小的差异。但请注意,服务器不需要发送(但它应该,如果可以的话)。

According to RFC 2616 section 13.3.4, an HTTP 1.1 Client MUST use the ETag in any cache-conditional requests, and if both an ETag and Last Modified are present, it SHOULD use both. The ETag header is considered a strong validator (see section 13.3.3), unless explicitly declared weak by the server, whereas the Last Modified header is considered weak unless at least a minute difference exists between it and the Date header. Note, however that the Server is not required to send either (but it SHOULD, if it can).

请注意,客户端不检查标题以查看它们是否存在已改变;它只是在下一个条件请求中盲目地使用它们;由服务器来评估是发送请求的内容还是304 Not Modified响应。如果服务器只发送一个,那么客户端将单独使用该服务器(尽管只有强验证器对Range请求有用)。当然,它也可以由中间缓存(除非它们已经通过缓存控制指令阻止缓存)和服务器如何对标头进行操作; RFC声明如果验证器不一致,它们不能返回304 Not Modified,但由于标头值是由服务器生成的,因此它有很大的余地。

Note that the Client does not check the headers to see if they have changed; it just blindly uses them in the next conditional request; it is up to the Server to evaluate whether to send the requested content or a 304 Not Modified response. If the Server only sends one, then the Client will use that one alone (although, only strong validators are useful for a Range request). Of course, it is also at the discretion of intermediate caches (unless they have been prevented from caching via Cache Control directives) and the Server as to how they will act upon the headers; the RFC states that they MUST NOT return a 304 Not Modified if the validators are inconsisent, but since the header values are generated by the server, it has quite a bit of leeway.

在实践中,我注意到Chrome,FireFox和IE 7+都发送了两个标头(如果有)。我还测试了发送修改标头时的行为,我已经从RFC中的信息中怀疑了这一点。我测试的四个客户端只在刷新页面时才发送条件请求,或者是第一次当前进程请求页面时发送了条件请求。

In practice, I have noticed that Chrome, FireFox, and IE 7+ all send both headers, if available. I also tested the behavior when sending modified headers, which I had already suspected from the information in the RFC. The four clients I tested only sent conditional requests if the page(s) were refreshed or if it was the first time the page had been requested by the current process.

这篇关于什么是优先:ETag或Last-Modified HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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