HTTP 304 Not Modified — What It Means and How to Fix It
The HTTP 304 (Not Modified) status code indicates that the client's cached copy of a resource is still fresh and can be used. The server is telling the client that the resource has not changed since the last time it was requested, thus saving bandwidth and server processing.
Essential Reading: Designing Data-Intensive Applications
The system design bible for software engineers. Learn to build reliable, scalable, and maintainable systems.
Common Causes
- Client sends conditional request headers (e.g., If-Modified-Since, If-None-Match) that match the server's current resource state.
- The resource on the server has not been updated since the timestamp or ETag provided by the client.
- Efficient caching mechanisms are in place on both the client and server sides.
Code Examples to Handle HTTP 304
curl -I https://httpbin.org/status/304
How to Fix It
- Verify that your server is correctly setting `Last-Modified` and/or `ETag` headers for cacheable resources.
- Ensure your client-side caching logic (e.g., browser, CDN) is sending appropriate conditional request headers.
- Inspect network requests in developer tools to confirm that `If-Modified-Since` or `If-None-Match` headers are being sent and that the server is responding with 304 when appropriate.
Related Status Codes
Frequently Asked Questions
What causes HTTP 304?
HTTP 304 is caused when a client sends a conditional request (using headers like `If-Modified-Since` or `If-None-Match`) for a resource, and the server determines that the resource has not been modified since the client's last request or since the ETag provided.
How do I fix HTTP 304?
You don't 'fix' HTTP 304 in the traditional sense, as it's an intended and beneficial response. Instead, you ensure your server correctly provides cache validation headers (`Last-Modified`, `ETag`) and that clients are sending conditional requests to leverage caching effectively. If you're unexpectedly getting a 304 when you expect new content, it means your server's cache validation headers are out of sync with the actual resource state, or your client isn't bypassing the cache when it should.