The If-None-Match
HTTP request header makes the request conditional. For {{HTTPMethod("GET")}} and {{HTTPMethod("HEAD")}} methods, the server will send back the requested resource, with a {{HTTPStatus("200")}} status, only if doesn't have a {{HTTPHeader("ETag")}} matching the given one. For other methods, the request will be processed only if the eventually existing resource's {{HTTPHeader("ETag")}} doesn't match any of the values listed.
The comparison with the stored {{HTTPHeader("ETag")}} uses the weak comparison algorithm, meaning two files are considered identical not only if they are identical byte to byte, but if the content is equivalent. For example, two pages that would differ only by the date of generation in the footer would be considered as identical.
When used in combination with {{HTTPHeader("If-Modified-Since")}}, it has precedence (if the server supports it).
There are two common use cases:
- For {{HTTPMethod("GET")}} and {{HTTPMethod("HEAD")}} methods, to update a cached entity that has an associated {{HTTPHeader("ETag")}}.
- For other methods, and in particular for {{HTTPMethod("PUT")}},
If-None-Match
used with the*
value can be used to save a file not known to exist, guaranteeing that another upload didn't happen before, losing the data of the previous put; this problems is the variation of the lost update problem.
Header type | {{Glossary("Request header")}} |
---|---|
{{Glossary("Forbidden header name")}} | no |
Syntax
If-None-Match: <etag_value> If-None-Match: <etag_value>, <etag_value>, … If-None-Match: *
Directives
- <etag_value>
- Entity tags uniquely representing the requested resources. They are a string of ASCII characters placed between double quotes (Like
"675af34563dc-tr34"
) and may be prefixed byW/
to indicate that the weak comparison algorithm should be used (This is useless withIf-None-Match
as it only uses that algorithm). *
- The asterisk is a special value representing any resource. They are only useful when uploading a resource, usually with {{HTTPMethod("PUT")}}, to check if another resource with the identity has already been uploaded before.
Examples
If-None-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d" If-None-Match: W/"67ab43", "54ed21", "7892dd" If-None-Match: *
Specifications
Specification | Title |
---|---|
{{RFC("7232", "If-None-Match", "3.2")}} | 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("ETag")}}
- {{HTTPHeader("If-Unmodified-Since")}}
- {{HTTPHeader("If-Modified-Since")}}
- {{HTTPHeader("If-Match")}}
- {{HTTPStatus("304")}}
Not Modified
- {{HTTPStatus("412")}}
Precondition Failed