What is a cache validation (conditional HTTP GET request) ?


A conditional get request or cache validation request is a conditional request made by the user agent to see if a stale resource is still valid.


If conditional headers leads to conditional requests. For instance:

If-Modified-Since: Sat, 07 Feb 2015 16:44:03 GMT
If-None-Match: "e026b5aa0e4be8d990f093176b3dcb7f"

Note that you can get one or both from the user agent (browser)

This conditional headers leads to conditional requests:

Headers Cache Validator Condition
If-Match ETag The Etag should be the same
If-None-Match ETag The Etag should not be the same
If-Modified-Since Last-Modified date The date should be more recent
If-Unmodified-Since Last-Modified date The date is older or the same
If-Range ETag or Last-Modified date Similar to If-Match, or If-Unmodified-Since for range request

The are known in the specification as Precondition Header Fields


The original fetch

The browser (or any other user-agent):

This header are called validator header because they will be send back to the server and will then permit to see if the resource has changed since the last fetch (hence validating the freshness of the cache).

sequenceDiagram participant Client participant Server Note left of Client: Initial Request
The cache is empty
and the request is not conditional Client->>Server: GET /doc/resource HTTP/1.1 Note right of Server: Resource Returned
One ore more validators are set Server->>Client: HTTP/1.1 200 OK
Last-Modified: date
Etag: "xyx"

The conditional request

When the resource becomes stale in the cache, the client may send a condition request to see if the resource is still valid. If this is the case and that the resource has not changed, the server sends back a 304 Not Modified response without the body making the request smaller in size.

The cache becomes fresh again, and the client uses the cached resource.

sequenceDiagram participant Client participant Server Note left of Client:
The cache is stal
A cache validation request
is send
with the conditional and
validator headers
Client->>Server: GET /doc/resource HTTP/1.1
Last-Modified Note right of Server: The server checks
if the resource has changed
with the validators
and returns a 304 or 200
alt if the resource has not changed (without body) Server->>Client: HTTP/1.1 304 OK
Last-Modified: date
Etag: "xyx" else if the resource has changed (with the body) Server->>Client: HTTP/1.1 200 OK
Last-Modified: date
Etag: "xyx" end

Documentation / Reference

Discover More
Chrome Devtool Network 304
304 - Not Modified HTTP Status

The 304 Not Modified indicates to the browser that the resource was not changed and that it can serve it from its cache
Etag - An unique identifier for a HTTP resource

The ETag HTTP response header is an identifier for a specific version of a resource. A etag comparison determines whether two representations of a resource are the same and is therefore similar to a hash...
HTTP - Cache (Cache-Control Header, Bursting, )

When sending a response, several headers have an influence / control over the cache store, we call them cache control headers The cache control header are: Name Description Cache-Control Define properties...
Http Status 304 Chrome Devtool
HTTP - Redirect (status codes 3xx) - Client must take additional action

The HTTP 3xx class of status code indicates that the client (user or user agent) must take additional action to complete the request. The redirect url is defined by the location header. A user agent...
HTTP - if-none-match Header

if-none-match is one of the conditional request header that permits to verify the freshness of the cache in a condition get request. As specified in a conditional get request, when a server gets a request...
HTTP Vary Header

The vary header adds a header value to the HTTP cache key entry
Chrome Devtool Network 304
How to implement and check a Web / HTTP cache ?

Implementing and verifying that the HTTP cache is set and working properly is not a straightforward task. This article gives you a step by step.
The Cache-Control HTTP header

The cache control header is the most important header in the HTTP cache mechanism and permits to turn it on or off alongside other properties.

Share this page:
Follow us:
Task Runner