The If-None-Match
HTTP header is a conditional request header used by clients to enable efficient caching and bandwidth usage. This header is sent by the client to the server to indicate that the requested resource should only be fetched if it does not match any of the specified entity tags (ETags). If the server has a matching ETag for the requested resource, it will respond with a 304 Not Modified
status, indicating that the client should use its cached version of the resource.
Usage
The primary purpose of the If-None-Match
header is to allow efficient caching of resources by avoiding unnecessary data transfers. When a client has a cached version of a resource, it can include the ETag of the cached resource in the If-None-Match
header when requesting the resource again. If the ETag on the server matches the one provided by the client, the server will not send the resource again, saving bandwidth and improving performance.
If-None-Match
can be used in combination with other conditional headers like If-Modified-Since
, but if both headers are present, If-None-Match
takes precedence.
Syntax
The If-None-Match
header consists of one or more entity tags (ETags) separated by commas. An ETag is a unique identifier assigned by the server to a specific version of a resource. The client can also use the wildcard *
to indicate that it does not have a cached version of the resource and wants to fetch it only if it exists on the server.
If-None-Match: "etag1", "etag2", "etag3"
Example
In this example, the client has a cached version of the resource with ETag "12345"
and requests the resource from the server.
Client Request
GET /resource HTTP/1.1
Host: example.com
If-None-Match: "12345"
If the server’s version of the resource has the same ETag ("12345"
), it will respond with a 304 Not Modified
status, indicating that the client should use its cached version.
Server Response (Resource Not Modified)
HTTP/1.1 304 Not Modified
ETag: "12345"
However, if the server’s version of the resource has a different ETag ("67890"
), it will send the updated resource along with its new ETag.
Server Response (Resource Modified)
HTTP/1.1 200 OK
ETag: "67890"
Content-Type: text/html
<!DOCTYPE html>
<html>
<head>
<title>Updated Resource</title>
</head>
<body>
<!-- Updated content -->
</body>
</html>
Summary
The If-None-Match
HTTP header is an essential tool for efficient caching and bandwidth usage. By including this header in requests, clients can avoid unnecessary data transfers and improve performance.