📚 Quick Definition
The resource has not been modified since the version specified by the If-Modified-Since or If-None-Match request headers. The server does not return a body - the client should use its cached copy. This is a critical part of HTTP caching that significantly reduces bandwidth usage.
⏱ When It Occurs
A 304 Not Modified response is returned when a client sends a conditional request (using If-None-Match or If-Modified-Since headers) and the server determines that the resource has not changed since the client last retrieved it. Instead of re-sending the entire resource, the server simply confirms the cached version is still valid.
🛠 Common Use Cases
- Browser cache validation for CSS, JavaScript, and image files
- CDN cache validation to reduce origin server load
- API response caching for frequently polled endpoints
- Conditional GET requests to check if data has been updated
- Reducing bandwidth for large resources that rarely change
- ETag-based cache validation for dynamic content
✅ Best Practices
- Implement ETag and Last-Modified headers on your server responses
- 304 reduces bandwidth significantly - a major performance optimization
- The 304 response must not include a response body
- Implement conditional requests in your API clients to leverage caching
- Combine with Cache-Control headers for a complete caching strategy
- Browsers handle 304 automatically for static assets - no extra code needed
📡 HTTP Example
GET /style.css HTTP/1.1 Host: www.example.com If-None-Match: "abc123"
HTTP/1.1 304 Not Modified ETag: "abc123" Cache-Control: max-age=3600 (no body - client uses cached version)