Understanding HTTP 304: Not Modified

Understanding HTTP 304: Not Modified

The HTTP 304 Not Modified status code is an important part of web performance optimization. It indicates that the requested resource has not changed since the time specified by the client in the request header.


When Does a Server Return HTTP 304?

A web server or CDN returns a 304 Not Modified response only when the following conditions are met:

  • The client includes the If-Modified-Since header in its HTTP request.

  • The resource on the server has not changed since the time specified in this header.


Example Scenario

Consider the following example:

  1. April 10: A browser requests a resource that is not yet in its cache. The response includes a caching policy (e.g., 7 days), and the browser stores the resource locally.

  2. April 12: The browser checks if the resource has changed by sending a request with:

    yaml

    CopyEdit

    If-Modified-Since: Thu, 10 Apr 2014 09:59:23 GMT

  3. If the resource has not been modified, the server responds with:

    yaml

    CopyEdit

    HTTP/1.1 304 Not Modified Last-Modified: Tue, 02 Mar 2014 11:03:22 GMT

This tells the browser to use its cached copy, improving speed and reducing bandwidth.


Behavior in Browsers and Clients

  • In web browsers, users will not see a 304 status. The browser silently serves the cached version of the resource.

  • In non-browser clients, the application must handle caching properly and respect If-Modified-Since or similar headers.

⚠️ If a client receives a 304 response but cannot present the cached resource, it is likely not managing conditional headers correctly.


Important Considerations

  • CDN Behavior: Some CDNs may ignore query strings when caching, depending on their configuration.

  • Browser Behavior: Browsers always use query strings when identifying cached resources. A difference in the query string means a new request will be made, bypassing the cache.