Which has the advantage: ETag header or Last-Modified HTTP?

For two subsequent queries, one of the following headers is given more weight to browsers if one of them changes: ETag or Last-Modified?

+73
caching etag
May 05 '09 at 9:55 a.m.
source share
3 answers

In accordance with RFC 2616 , section 13.3.4, an HTTP 1.1 client MUST use an ETag in any cache-related requests, and if both ETag and Last Modified MUST use both. An ETag header is considered a strong validator (see Section 13.3.3) unless explicitly indicated by a weak server, while a Last Modified header is considered weak if there is not even a minute difference between it and the date header. Note, however, that the server is not required to send (but it MUST, if possible).

Please note that the Client does not check the headers to see if they have changed; he just blindly uses them in the next conditional query; the server must evaluate whether to send the requested content or a 304 Not Notified response. If the server sends only one, then the Client will use it alone (although only strong validators are useful for requesting a range). Of course, it is also at the discretion of the intermediate caches (unless they were protected from caching using Cache Control directives) and the server as to how they will affect headers; The RFC states that they SHOULD NOT return 304 Not Modified if the validators are inconsistent, but since the header values ​​are generated by the server, it has quite a bit of freedom.

In practice, I noticed that Chrome, FireFox, and IE 7+ send both headers, if available. I also tested the behavior of sending modified headers, which I already suspected of information in the RFC. The four clients I tested sent only conditional requests if the pages were refreshed or this was the first time the page was requested by the current process.

+82
Oct 13 '09 at 13:01
source

Isn't that like the expression "OR". In pseudo code:

if ETagFromServer != ETagOnClient || LastModifiedFromServer != LastModifiedOnClient GetFromServer else GetFromCache 
+19
May 05 '09 at 10:12 a.m.
source

=! is the correct comparison operator. The client must store the letter string received from the server, as conversions can create small differences. You cannot assume that "newer is better."

Why? Consider the case when the server operator returns a bad version of the resource. The returned version of OLDER is correct.

The client must use the version currently offered by the server; it can use the cached version only if it is the same. Thus, the server should check for equality, not "new."

+4
Nov 14 '14 at 12:48
source



All Articles