304 Not Modified
Server returns the 304 HTTP response status code to indicate a successful HTTP request, yet it's not required to send the data associated with the relevant resource.
When you receive the HTTP response status code 304 Not Modified, it means that your request was successful, but the requested resource has not changed since your last request.
Instead of sending the full data again, the server simply sends a header indicating that the resource is unchanged, saving bandwidth and speeding up the process.
The 304 Not Modified status code is used by the server when it determines that the requested resource has not changed since the client's last request.
This is particularly useful for safe HTTP requests like GET or HEAD, as it allows the server to save bandwidth by not retransmitting data the client already has.
The server will include specific HTTP headers like Cache-Control, ETag, or If-Modified-Since to assess whether the resource needs to be transmitted again, ensuring an efficient cache-update process.
In the example, the client initially requests a resource, and the server sends a unique identifier called ETag to represent that version.
When the client makes subsequent requests, it includes the ETag it received earlier to check if anything has changed. If the resource remains unchanged, the server responds with a 304 Not Modified status code, saving bandwidth. However, if the resource has been updated, the server transmits the latest version with a new ETag.
This process, along with the server-side version history and the client's local cache, helps conserve bandwidth and optimize data retrieval. Alternatively, the server can use the Last-Modified date, eliminating the need for ETag version history.
Initial request
GET /news.html HTTP/1.1
Host: www.example.com
Initial response
HTTP/1.1 200 OK
Etag: “1234 … 000″
Content-Type: text/html
Content-Length: 1250
< message body contains requested resource>
Second request
GET /news.html HTTP/1.1
Host: www.example.com
If-None-Match: “1234 … 000″
Second response
HTTP/1.1 304 Not Modified
Etag: “1234 … 000″
Third request
GET /news.html HTTP/1.1
Host: www.example.com
If-None-Match: “1234 … 000″
Third response
HTTP/1.1 200 OK
Etag: “1234 … 001″
Content-Type: text/html
Content-Length: 1600
< message body contains requested resource>
The 304 Not Modified status code is used by the server to indicate that a requested resource has not changed since the client's last request. This saves bandwidth and optimizes data retrieval by allowing the client to use its cached version of the resource, avoiding unnecessary data transmission.