304 Status Code - Not Modified
In this section you will learn about 304 Status Code, what is it, its components and examples.
What is HTTP Status Code 304 - Not Modified?
The HTTP Status Code 304, termed as "Not Modified", is a special redirection response status code. Unlike other redirection codes that tell the client where to find the resource,
304 Not Modified informs the client that the version of the resource they currently have in cache is still the latest one, and there's no need to re-fetch it. This is particularly useful for optimizing web performance by reducing unnecessary data transfer.
Understanding 304 Not Modified
Cache Verification: The
304 Not Modifiedresponse is often tied to cache mechanisms. When a client possesses a cached version of a resource, it can check with the server if that version is still valid. If it is, the server returns a
304 Not Modified.
Etag & Last-Modified Headers: To facilitate this cache validation, the server often uses headers like
Last-Modified. When the client makes a subsequent request, it includes these headers, and the server can then determine whether the resource has changed since the last fetch.
Why 304 Not Modified?
304 Not Modified status code is instrumental in enhancing web performance. By informing the client that their cached resource is still valid, it eliminates the need for re-downloading the same data, thus saving bandwidth and speeding up load times.
Benefits of 304 Not Modified
Optimized Web Performance: By preventing unnecessary data transfers, load times are improved, leading to a smoother user experience.
Bandwidth Conservation: Especially for large web resources or users with limited bandwidth, using the cache effectively can lead to substantial bandwidth savings.
How does 304 Not Modified Work?
Client Sends a Conditional Request:
The client, possessing a cached resource, sends a request to the server, including headers like
If-None-Match(for Etags) or
If-Modified-Since(for Last-Modified) to check if the resource has changed.
Server Evaluates & Responds:
The server checks the resource against the provided headers. If the resource hasn't changed, it returns a
304 Not Modified. If it has, it sends the updated resource.
Components of a 304 Not Modified Response
304 Not Modified response generally contains:
Status Line: Signifying the
304 Not Modifiedstatus code.
Headers: While the response body remains empty (since the resource isn't sent), headers like
Cache-Control, and others can still be included.
Example of 304 Not Modified
Here, the client has an image (
logo.png) cached and is checking if the version from October 21, 2020, is still the latest. The server confirms that the image hasn't changed since that date, so it returns a
304 Not Modified, and the client uses its cached version.
304 Not Modified status code is a cornerstone of efficient web performance, leveraging caching mechanisms to provide users with faster load times and reduce server load. By ensuring that only modified or new resources are fetched, it optimizes bandwidth use and offers a more streamlined web experience.