Skip to content

Last-Modified

Description

The Last-Modified response header contains the date and time at which the server believes the resource was last modified. This header provides clients with information about the age of the resource, allowing them to make conditional requests based on modification time, which can improve efficiency and reduce bandwidth usage.

When a client has a cached copy of a resource, it can use the If-Modified-Since request header with the value from a previous Last-Modified response. If the resource hasn't changed since that time, the server can respond with a 304 Not Modified status without sending the resource again, saving bandwidth.

The Last-Modified header works in a similar way to the ETag header, but instead of using content-based identifiers, it uses timestamps. While generally less precise than ETags (since modification times are often rounded to the nearest second), it's widely supported and simpler to implement.

Syntax

The syntax of the Last-Modified header follows this structure:

Last-Modified: <http-date>
  • <http-date>: A date and time in the HTTP date format (same format as the Date header).

The date must be in the format defined by RFC 7231:

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

Example Syntax

Last-Modified: Sun, 01 Jun 2025 13:45:30 GMT

This example indicates that the resource was last modified at 13:45:30 GMT on June 1, 2025.

Examples

Basic Example

A response with a Last-Modified header:

HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 12:00:00 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 1234
Last-Modified: Sat, 31 May 2025 18:30:00 GMT

<!DOCTYPE html>
<html>
<head><title>Example Page</title></head>
<body><p>This page was last modified on May 31, 2025.</p></body>
</html>

Conditional Request Example

A client making a conditional request with If-Modified-Since:

GET /resource HTTP/1.1
Host: example.com
If-Modified-Since: Sat, 31 May 2025 18:30:00 GMT

If the resource hasn't been modified since the specified date, the server responds:

HTTP/1.1 304 Not Modified
Date: Mon, 02 Jun 2025 12:10:30 GMT
Last-Modified: Sat, 31 May 2025 18:30:00 GMT
Cache-Control: max-age=86400

If the resource has been modified, the server sends the updated content:

HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 12:10:30 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 1345
Last-Modified: Mon, 02 Jun 2025 09:15:00 GMT

<!DOCTYPE html>
<html>
<head><title>Updated Example Page</title></head>
<body><p>This page was updated on June 2, 2025.</p></body>
</html>

Static File Example

A response for a static image file:

HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 12:20:45 GMT
Content-Type: image/png
Content-Length: 23456
Last-Modified: Wed, 15 Jan 2025 10:00:00 GMT
Cache-Control: public, max-age=31536000

[... PNG data ...]

In this example, the image hasn't been modified since January 15, 2025, and the server allows it to be cached for one year.

Summary

The Last-Modified response header provides a simple yet effective mechanism for optimizing web performance through conditional requests. By indicating when a resource was last changed, this header enables clients to avoid redundant downloads when their cached copy is still current. While not as precise as ETags, the Last-Modified header is widely supported and easy to implement, making it a staple of efficient HTTP caching strategies. When used in conjunction with conditional request headers like If-Modified-Since, it helps reduce bandwidth usage, server load, and improves response times for clients with cached content.