HTTP ETag and Conditional Requests — If-None-Match and 304 Not Modified
Informational3xx redirection
Overview
Master HTTP conditional requests using ETag, If-None-Match, If-Match, and 304 Not Modified responses for efficient caching and optimistic concurrency control.
Key Details
- ETag (Entity Tag) is a unique identifier for a specific version of a resource
- If-None-Match: sends the cached ETag — server returns 304 if unchanged, 200 with new data if changed
- If-Match: used for write operations — server rejects the update with 412 if the ETag changed (optimistic locking)
- Strong ETags ("abc123") indicate byte-for-byte identical content; weak ETags (W/"abc123") indicate semantically equivalent
- ETags reduce bandwidth by avoiding redundant full-content responses
Common Causes
- Server not generating ETags, forcing full content download on every request
- ETag mismatch during updates causing 412 Precondition Failed (concurrent edit detected)
- Load balancer routing requests to different servers with different ETag generation
- CDN caching stale ETags after content updates on the origin server
Steps
- 1Enable ETag generation on your server: Nginx and Apache generate ETags by default for static files
- 2For APIs: generate ETags from a hash of the response body or the resource's last-modified timestamp
- 3Include If-None-Match in GET requests to enable 304 responses and reduce bandwidth
- 4Use If-Match in PUT/PATCH requests to prevent lost updates from concurrent editing
- 5Ensure all servers behind a load balancer generate identical ETags for the same content
- 6After a 412 Precondition Failed: re-fetch the current version, merge changes, and retry the update
Tags
etagconditional-request304if-none-matchcache-validation
Related Items
More in 3xx Redirection
http-300-multiple-choicesHTTP 300 Multiple Choices — What It Means & How to Fix It
Warninghttp-301-moved-permanentlyHTTP 301 Moved Permanently — What It Means & How to Fix It
Warninghttp-302-foundHTTP 302 Found — What It Means & How to Fix It
Warninghttp-303-see-otherHTTP 303 See Other — What It Means & How to Fix It
Warninghttp-304-not-modifiedHTTP 304 Not Modified — What It Means & How to Fix It
Warninghttp-305-use-proxyHTTP 305 Use Proxy — What It Means & How to Fix It
WarningFrequently Asked Questions
ETag is content-based (hash of the content), Last-Modified is time-based. ETag is more precise — it detects changes even if the modification time is the same. Use both for maximum compatibility.