What is an HTTP conditional request?
Useful first: HTTP · optional, not a requirement
Choose your depth
Stay with the essentials, or look closer.
YOUR GOALUnderstand why a request can depend on whether a shared document changed.
Check the version before acting
Two people edit the same packing list
Imagine that Maya and Leo open the same workshop packing list. Maya adds batteries and saves. Leo is still looking at the older list; if he replaces the server copy with his version, Maya’s addition can disappear. This is a lost update.
A conditional request lets Leo’s app say: “Save my change only if the version I started with is still current.” The server checks that condition before making the requested change. The HTTP guide explains the surrounding request and response.
[1] [3]A version label is a check, not a reservation
The server can attach an ETag: an opaque label for a representation’s version. The app keeps the label with the document and sends it back when it needs a version check. The label is not necessarily a readable revision number or a content hash.
Think of writing a revision code on a photocopy. It helps you compare copies, but does not stop anyone editing the original. Likewise, merely receiving an ETag does not lock a document. The app must make a conditional request and the server must enforce the check.
[2] [1]A conditional request checks an assumption at the server before acting on it.
Receiving an ETag prevents anyone else from editing the document.
An ETag identifies a version. It does not reserve or lock that version for one reader.
Show the explanation
Accidentally replacing Maya’s newer work with Leo’s older starting version. The server can refuse an update based on an outdated version, giving Leo a chance to reconcile the changes.
YOUR GOALDistinguish a guarded save from a cache check and interpret their different responses.
Choose the condition for the job
Use If-Match for a guarded save
Suppose the app received the list with ETag: "list-17". A later save can include the following request line and header; this is an illustrative fragment, not a complete request:
PUT /notes/packing-list HTTP/1.1
If-Match: "list-17"If the current strong ETag is still "list-17", the version precondition passes. If Maya’s different edit has produced "list-18", the server refuses this stale save with 412 Precondition Failed. Leo’s app should fetch the current list, reconcile the edits, and submit against the new version. Removing the condition would discard that safeguard.
Use If-None-Match to check a saved response
A cache asks a different question: “Send the content if my saved version no longer matches.” For a normal successful read, it can send If-None-Match: "list-17" with GET.
If that tag matches the selected representation, the response is 304 Not Modified, with no response body to replace the saved one. If it does not match, the server can send the current content in a 200 OK response. The request still uses the network; 304 does not mean a new document body was downloaded.
Distinguish a failed condition from a missing one
In the guarded-save example, 412 means the supplied precondition did not hold. 428 Precondition Required means the server requires a conditional request, commonly because a required If-Match header was omitted.
Not every service requires conditional writes. Read the API’s contract: a service that demands a version check can use 428 to ask the client to obtain the current version and provide the appropriate condition. Neither status means the server has automatically merged competing edits.
[4] [7]Use a match to protect a change, and a non-match to decide whether a saved response needs replacing.
304 and 412 both mean that a new version was downloaded.
A 304 response has no body and supports reuse of a saved response. A 412 reports that a request precondition failed.
Show the explanation
Fetch the current version and reconcile the edits before another conditional save. The version assumption failed. Fetching and reconciling preserves the chance to keep both users’ intended changes.
YOUR GOALChoose strong validators, distinguish existence checks from version checks, and recognize the limits of preconditions.
Understand comparison and enforcement
Strong and weak tags serve different comparisons
ETag: "list-17" is a strong tag; ETag: W/"list-17" is weak. If-Match uses strong comparison, so a weak tag cannot satisfy a listed-tag If-Match check, even when its opaque text looks the same. If-None-Match uses weak comparison, which can treat semantically equivalent representations as matching.
Do not remove W/ to manufacture a strong validator. Use a validator the server actually provides for the operation. A date-based If-Unmodified-Since can express “unchanged since this time” when an entity tag is unavailable; it compares the resource’s modification time with the supplied date.
Create only if absent is an existence condition
For an otherwise valid PUT to a chosen URL, If-None-Match: * asks the server to proceed only when the target has no current representation. If one already exists, the precondition fails and the server returns 412 instead of overwriting it.
The opposite wildcard, If-Match: *, checks that a current representation exists. It does not check that the existing document is the particular version you previously read. Use that version’s strong ETag when the goal is to prevent a lost update.
A condition is only one part of the request
Normal request checks come before precondition evaluation, so a matching ETag does not grant access or make an invalid operation valid. At the origin, If-Match takes precedence over If-Unmodified-Since; for cache checks, If-None-Match takes precedence over If-Modified-Since. Adding more conditional headers does not make every one an independent extra check.
The origin must enforce a write precondition before applying the change. A client-side “check, then save” without a server-enforced condition leaves room for another edit between those steps. RFC 9110 also permits success for a state-changing request that the server determines has already succeeded; a failed If-Match does not authorize applying a new conflicting change. For resuming downloads, If-Range has a different fallback.
[8]Match the validator and comparison to the operation, and let the server enforce the condition at the point of change.
If-Match: * proves the server still has the exact version I read.
The wildcard checks existence. A listed strong ETag can check the specific representation version.
Show the explanation
If-None-Match: * If-None-Match with * makes the operation conditional on absence; If-Match with * instead requires existence.
Keep asking. Check the details.
Source-checked using AI (OpenAI Codex) on . The checks covered sources, examples, and quizzes for this article version.
No human review is claimed. AI review can miss errors; check the original sources below.
- MDN — HTTP conditional requests
- MDN — ETag
- MDN — If-Match
- MDN — 412 Precondition Failed
- MDN — If-None-Match
- MDN — 304 Not Modified
- MDN — 428 Precondition Required
- RFC 9110 — Preconditions and their evaluation
- MDN — If-Unmodified-Since