Card 04/ 11
A Conditional GET: If-None-Match and 304
The client sends the ETag it has; the server answers 304 with no body if nothing changed.
A conditional GET asks for a resource only if it has changed since the version the client holds. The client sends the ETag it stored in an If-None-Match header; if the resource still has that ETag, the server answers 304 Not Modified with no body, and the client reuses its copy. Here is the exchange for an order whose cached copy has gone stale. The ETags are illustrative.
The conditional GET, step by step
The first request gets the body and a validator
The server answers 200 OK with the order, ETag: "v7" and Cache-Control: max-age=60. The client, or its HTTP cache, stores the body and the tag together.
The copy goes stale
After 60 seconds the copy is stale. It is not thrown away; it can still be used once the server confirms it.
The client asks if it has changed
The next request carries If-None-Match: "v7". It means: send the order only if its current ETag is not v7.
Unchanged, the server sends 304
The server finds the current ETag is still v7 and answers 304 Not Modified with no body. It sends the headers that update the copy, such as a new Cache-Control, so the stored order is fresh for another 60 seconds.
Changed, the server sends the new version
Once the order ships its ETag becomes v8, so the condition passes and the server answers 200 OK with the new body and ETag: "v8", which replaces the stored copy.
What is saved. A 304 carries no body, so a large list costs a few hundred bytes instead of hundreds of kilobytes. If the server can compute the ETag without building the response, for example from a version column, it also saves the database work.
What is not saved. The round trip still happens. Revalidation saves bandwidth and server work, not latency; only a fresh copy within max-age saves the trip.
Who does the work. Browsers and most HTTP client libraries with a cache send If-None-Match and handle the 304 themselves. The server's job is to send the ETag and honour the header.
← → move through sections and cards