HTTP 304 Not Modified vs 412 Precondition Failed
HTTP 304 (Not Modified) is a 3xx Redirection response, while 412 (Precondition Failed) is a 4xx Client Error response. 304 indicates that the resource has not been modified since the last request. The client can use its cached copy. In contrast, 412 means that one or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false.
Description
The resource has not been modified since the last request. The client can use its cached copy.
When You See It
When the browser cache is still valid (If-None-Match / If-Modified-Since headers match).
How to Fix
No fix needed. This saves bandwidth by confirming the cached version is still current.
Description
One or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false.
When You See It
When using conditional requests with ETags and the resource has changed.
How to Fix
Refresh the ETag/Last-Modified value and retry with updated preconditions.
Key Differences
304 is a 3xx Redirection response, while 412 is a 4xx Client Error response.
HTTP 304: The resource has not been modified since the last request. The client can use its cached copy.
HTTP 412: One or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false.
You encounter 304 when when the browser cache is still valid (If-None-Match / If-Modified-Since headers match).
You encounter 412 when when using conditional requests with ETags and the resource has changed.
When to Use Which
For 304 (Not Modified): No fix needed. This saves bandwidth by confirming the cached version is still current. For 412 (Precondition Failed): Refresh the ETag/Last-Modified value and retry with updated preconditions.