What is a conditional HTTP request?
Quick answer
A conditional HTTP request asks a server to process a request only if a stated condition about a resource is met. The condition uses a validator, such as an ETag or Last-Modified date. For a GET request, this can let the server indicate that cached content is unchanged; for an update, it can help prevent overwriting a resource that changed since it was read. The effect depends on server support and the condition used. [S1]
The question, the details, the next step.
A practical checklist
Decide whether your goal is to validate a cached GET response or guard an update.
Check whether the server supplies or accepts a validator for the resource.
Choose a condition that matches the operation; do not treat cache validation and update protection as interchangeable.
For a controlled test, record the request condition and the server’s response when the resource is unchanged and when it has changed.
Plan how your client will respond if an update precondition fails, rather than assuming the server applied the update.
A few more useful answers
Does a `304 Not Modified` response mean the server sent a fresh copy?
No. In the described GET case, it indicates that the content is unchanged, avoiding retransmission; the client can use its stored copy. [S1]
Does using an update condition guarantee that no changes can be overwritten?
No universal guarantee follows from the mechanism alone. Its practical effect depends on server support and the condition used. [S1]
What does `412 Precondition Failed` mean in this context?
It can indicate that an update’s precondition failed, such as when the resource changed since it was read. [S1]
Sources
References used for this guide.
- [S1] HTTP conditional requests — MDN Web Docs developer.mozilla.org · Checked
