concept Delivery & performance
ETag and conditional requests
An HTTP ETag is an opaque representation validator.
What it means
An HTTP ETag is an opaque representation validator. A client can send it back with a conditional request to avoid receiving an unchanged representation or to prevent an unintended write. If-None-Match uses weak comparison for conditional retrieval and can produce 304 Not Modified for matching GET/HEAD; If-Match uses strong comparison to protect a modification and can produce 412 Precondition Failed. Weak validators prefixed W/ do not satisfy strong comparison.
Try it
Simulation — compare validators. Set the stored client tag and current resource tag to "v1" and request GET with If-None-Match: the result is 304 without response content. Change the current tag to "v2" for a full 200 representation. Switch to PUT with If-Match and try the weak W/"v1": it fails a strong check. Run a matching strong guarded write and inspect the new virtual validator; a later stale write should fail. Reset discards the virtual update.
ETag preconditions
Compare validators for GET revalidation or a guarded PUT; view response and virtual representation state.
Weak comparison matched: a 304 supplies no representation body.
| Observation | Model value |
|---|---|
| Method | GET |
| Condition | If-None-Match |
| Client | "v1" |
| Current before first request | "v1" |
| Strong comparison? | false |
| Match now? | true |
| Response | 304 |
| Response body? | None |
| Stored validator after step | "v1" |
| Virtual stage | Initial request preview |
Local, bounded educational fixture. No DNS, mail, certificate, network, socket or external request is performed.
About this model
ETags are opaque validators, not necessarily hashes. If-None-Match uses weak comparison; If-Match uses strong comparison. No actual HTTP or persisted writes occur.
See the article’s protocol sources and model limits. The scene does not alter a real system.
How the mechanism works
A server chooses opaque entity-tag values. Clients must not assume an ETag is always a file hash, timestamp or portable identifier for a resource across representations. Weak tags allow semantically equivalent representations under the relevant comparison; strong comparison demands matching opaque tags without weakness. The same literal-looking tag can produce different conditional behavior depending on the header and method.
On a matching If-None-Match GET, the server can send 304 and selected representation metadata; the client uses a previously stored body according to cache rules. For a conditional PUT, a failing If-Match protects against overwriting a changed version and normally produces 412. An accepted update can change the ETag; repeating the previous strong precondition then becomes stale. The exercise distinguishes the status of a response from the state of its virtual representation.
Primary protocol documentation provides the underlying rules; the interactive state is only a synthetic illustration.
In practice
For collaborative editing or API updates, read the server's actual ETag/precondition contract and test a normal fetch, one update and a concurrent stale update in an isolated environment. Do not assume all APIs support PUT, return ETags or choose validators identically. Stop if a client gets 412 or a version mismatch; refetch state and resolve conflicts instead of retrying writes without conditions. Keep an application-level rollback/restore mechanism for modifications.
Limits and common mistakes
This model allows just GET, HEAD and PUT with If-None-Match/If-Match and a few fixed ETags. It does not cover wildcard conditions, full precondition precedence, partial representations, all response headers or actual persistence. Its write is local to memory only.
Key takeaways
An ETag is an opaque representation validator, not necessarily a content hash. If-None-Match supports weak comparison for cache validation; If-Match requires strong comparison for guarded writes. A successful virtual update changes the validator, so a later stale precondition must be tested against the new state, not replayed as success.
Frequently asked questions
Editorial questions, answered from the sources listed for this article.
Why did matching ETag produce 304 once and 412 another time?
The precondition and method differ. A matching If-None-Match on GET can produce 304; a failed strong If-Match guard on PUT produces 412.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- HTTP Semantics
HTTP method, status (§15), redirection (§15.4) and validators/preconditions (§§8,13). Statuses, redirects/methods, conditional requests and validators.
Checked .
- HTTP Caching
Storage, cache freshness and revalidation (§§3–5). Cache directives, freshness, validation and shared/private restrictions.
Checked .
- MDN — ETag header
ETag, conditional retrieval and weak/strong validators. Opaque validators, conditional reads/updates; not a mandatory content-hash format.
Checked .