Error Codes Wiki

HTTP ETag and Conditional Requests — If-None-Match and 304 Not Modified

Informational3xx redirection

About HTTP ETag and Conditional Requests

Master HTTP conditional requests using ETag, If-None-Match, If-Match, and 304 Not Modified responses for efficient caching and optimistic concurrency control. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Enable ETag generation on your server: Nginx and Apache generate ETags by default for static files. For APIs: generate ETags from a hash of the response body or the resource's last-modified timestamp. Include If-None-Match in GET requests to enable 304 responses and reduce bandwidth. Use If-Match in PUT/PATCH requests to prevent lost updates from concurrent editing. Ensure all servers behind a load balancer generate identical ETags for the same content. After a 412 Precondition Failed: re-fetch the current version, merge changes, and retry the update. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

What is the difference between ETag and Last-Modified?

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.

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

  1. 1Enable ETag generation on your server: Nginx and Apache generate ETags by default for static files
  2. 2For APIs: generate ETags from a hash of the response body or the resource's last-modified timestamp
  3. 3Include If-None-Match in GET requests to enable 304 responses and reduce bandwidth
  4. 4Use If-Match in PUT/PATCH requests to prevent lost updates from concurrent editing
  5. 5Ensure all servers behind a load balancer generate identical ETags for the same content
  6. 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

Frequently 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.