/ HTTP Headers

If-Modified-Since

The If-Modified-Since HTTP header is a request header used by clients to conditionally fetch resources from a server, based on the modification date of the resource. This header helps clients optimize their requests by only fetching resources that have been modified since the specified date.

How If-Modified-Since Works

When a client sends an HTTP request with the ‘If-Modified-Since’ header, the server checks the modification date of the requested resource. If the resource has been modified since the specified date, the server sends the updated resource along with a 200 OK status. If the resource has not been modified, the server returns a 304 Not Modified status, indicating that the client can continue using its cached version of the resource.

The If-Modified-Since header is particularly useful for reducing bandwidth usage and improving the performance of web applications, as it allows clients to avoid downloading resources that haven’t changed since their last request.

Syntax

The header uses the following syntax:

If-Modified-Since: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT

The date and time values must be formatted according to the HTTP-date specification, which is based on the RFC 1123 date format.

Example: Using If-Modified-Since in a Request

Here’s an example of an HTTP request that includes the header:

GET /example-resource.html HTTP/1.1
Host: www.example.com
If-Modified-Since: Tue, 15 Nov 1994 12:45:26 GMT

In this example, the client is requesting the /example-resource.html resource from www.example.com. The If-Modified-Since header indicates that the client only wants to receive the resource if it has been modified since Tue, 15 Nov 1994 12:45:26 GMT.

Example: Server Responses to If-Modified-Since Requests

Response with Updated Resource

If the server determines that the requested resource has been modified since the specified date, it returns the updated resource along with a 200 OK status:

HTTP/1.1 200 OK
Date: Mon, 01 Jan 2023 12:00:00 GMT
Content-Type: text/html
Content-Length: 1234

<!DOCTYPE html>
<html>
...
</html>

Response without Updated Resource

If the server determines that the requested resource has not been modified since the specified date, it returns a 304 Not Modified status without the resource:

HTTP/1.1 304 Not Modified
Date: Mon, 01 Jan 2023 12:00:00 GMT

In this case, the client can continue using its cached version of the resource.

Summary

The If-Modified-Since HTTP header allows clients to conditionally fetch resources based on their modification date. This header helps optimize bandwidth usage and improve web application performance by enabling clients to avoid downloading resources that haven’t changed since their last request.

Was this helpful?

Thanks for your feedback!