HTTPQUERY
English

Last-Modified

Usage

The Last-Modified header serves as a weak validator for conditional requests. When a client caches a response containing Last-Modified, the client stores the timestamp and sends the date back in the If-Modified-Since request header on subsequent requests. The server compares the stored date against the current modification time of the resource. If the resource has not changed, the server returns 304 Not Modified with no body. If the resource has changed, the server sends the full updated response.

The If-Unmodified-Since header uses the same timestamp for precondition checks on unsafe methods like PUT and DELETE, returning 412 Precondition Failed when the resource has been modified since the given date.

The Last-Modified date is less precise than an ETag. Timestamps have one-second granularity, so changes within the same second are invisible to date-based validation. The ETag header provides a stronger validator tied to the exact content. When both Last-Modified and ETag are present in a response, ETag takes priority during revalidation.

The date value follows the HTTP-date format: day name, two-digit day, abbreviated month, four-digit year, time in hours, minutes, and seconds, followed by GMT. The format is Weekday, DD Mon YYYY HH:MM:SS GMT.

Last-Modified: Fri, 04 Sep 1998 19:15:56 GMT

Example

A response with the modification date of the resource. The client stores this timestamp for future conditional requests.

Last-Modified: Wed, 01 Jun 2022 08:00:00 GMT

A full conditional request cycle. The server sends Last-Modified with the initial response. On the next request, the client echoes the timestamp in If-Modified-Since. The server returns 304 if the resource has not changed.

HTTP/1.1 200 OK
Last-Modified: Wed, 01 Jun 2022 08:00:00 GMT
Cache-Control: max-age=86400
Content-Type: text/html

Subsequent request:

GET /page HTTP/1.1
If-Modified-Since: Wed, 01 Jun 2022 08:00:00 GMT

Server response when unchanged:

HTTP/1.1 304 Not Modified
Last-Modified: Wed, 01 Jun 2022 08:00:00 GMT
Cache-Control: max-age=86400

A response pairing Last-Modified with an ETag. The ETag provides a strong validator while the modification date provides a fallback for clients supporting only date-based validation.

Last-Modified: Fri, 22 Nov 2024 14:30:00 GMT
ETag: "a1b2c3d4"
Cache-Control: max-age=3600