304 Not Modified
Indicates that the resource has not been modified since the version specified by the request headers.
Usually happens because:
- ☑ Client requests carrying cached ETag
- ☑ Client requests with If-Modified-Since values
🔍 Quick Checklist:
Meaning
The HTTP 304 Not Modified redirection status code indicates that there is no need to re-transmit the requested resources. It is an implicit redirection to a cached local copy. This code is returned when conditional headers (e.g., If-None-Match, If-Modified-Since) verify no changes.
Root Causes
- Client requests carrying cached ETag hashes matching server resource state ETag.
- Client requests with If-Modified-Since values newer than server last-modified timestamps.
| Cause | Frequency |
|---|---|
| Client requests carrying cached ETag | ⭐⭐⭐⭐⭐ |
| Client requests with If-Modified-Since values | ⭐⭐⭐⭐ |
Common Mistakes
- Sending a response body payload on a 304 response, causing connection errors.
- Miscalculating ETag values, resulting in clients getting stale cached assets.
How to Fix
Framework-Specific Examples
Express conditional caching using ETag middleware.
app.get('/data', (req, res) => {
const data = { id: 1 };
res.setHeader('ETag', 'hash-123');
if (req.headers['if-none-match'] === 'hash-123') {
return res.status(304).end();
}
res.json(data);
});Server Configuration Examples
Nginx conditional header caching settings.
etag on;
expires 1h;Prevention
- Use server-level ETag filters (like Nginx etag on) to automate caching validations.
- Verify cache headers (Cache-Control, Last-Modified) are configured consistently.
Frequently Asked Questions (FAQ)
Q: Does a 304 response contain a body?
No. A 304 response must not contain a message body. Any headers that would describe the body (like Content-Length) should refer to the cached representation.
Q: What triggers a 304 response?
A 304 is triggered when the client sends conditional validation headers (If-None-Match or If-Modified-Since) and the server verifies that the resource state hasn't changed.
Q: How does 304 Not Modified help server performance?
It eliminates the need to download large files again, dramatically reducing network bandwidth consumption and speeding up page rendering.
Q: What is an ETag?
An Entity Tag (ETag) is a unique string hash generated by the server representing a specific version of a resource file.