The ETag
HTTP response header is an identifier for a specific version of a resource. It allows caches to be more efficient, and saves bandwidth, as a web server does not need to send a full response if the content has not changed. On the other side, If the content has changed, Etags can be useful to prevent simultaneous updates of a resource from overwriting each other ("mid-air collisions").
If the resource at a given URL changes, a new Etag should be generated. Etags are therefore similar to fingerprints. A comparison of them allows to quickly determine whether two representations of a resource are the same.
Header type | {{Glossary("Response header")}} |
---|---|
{{Glossary("Forbidden header name")}} | no |
Syntax
ETag: "W/" "<etag_value>" ETag: "<etag_value>"
Directives
- "W/" {{optional_inline}}
- "W/" (case-sensitive) indicates that a weak validator is used. Weak validators are easy to generate but are far less useful for comparisons. Strong validators are ideal for comparisons but can be very difficult to generate efficiently. Weak Etags of two representations might be semantically equivalent, but not byte-for-byte identical.
- "<etag_value>"
- Entity tags uniquely representing the requested resources. They are a string of ASCII characters placed between double quotes (Like
"675af34563dc-tr34"
). The method by which ETag values are generated is not specified. Oftentimes, a hash of the content, a hash of the last modification timestamp, or just a revision number is used. MDN uses a hash of hexadecimal digits of the wiki content, for example.
Examples
ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4" ETag: "W/" "0815"
Specifications
Specification | Title |
---|---|
{{RFC("7232", "ETag", "2.3")}} | Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests |
Browser compatibility
The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data/README.md and send us a pull request.
{{Compat}}
See also
- {{HTTPHeader("If-Match")}}
- {{HTTPHeader("If-None-Match")}}