HTTP headers | Last-Modified

The last modified response header is a header sent by the server specifying the date of the last modification of the requested source. This is the formal definition of Last-Modified of HTTP headers, let’s break it down.

Suppose you have created a website and set the last-modified header. When a user browses your website, the user’s browser temporarily stores (caches) some information like HTML, images, style-sheets and even some infrequently changing dynamic content. All browsers always cache the resources by default, so no special header response is required.
Now the user likes your website and visits it again! This time you are even better than before. The server will check whether you have updated the website since the user’s last visit. If there is no change, the server sends a “304 not modified” reply to the browser, and the information loads from the local cache.

The last-modified header is a response header used with a request header called “If modified” header. The If-modified header sends a request to the server to know when the resource was last modified. The last-modified header tells the browser when the resource was last modified, and whether it should use the cached copy or download the newer version of the website. These are cache-control headers.



Syntax:

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

Note: The Last-modified header looks like this: Last-Modified: Tue, 15 Oct 2019 12:45:26 GMT

Directives:

  • <day-name>: It contains the days name like “Mon”, “Tue” etc. (case-sensitive).
  • <day>: It contains the date in 2 digit number, like “04” or “23” for days.
  • <month>: It contains the name of the month, in 3 letter month names like “Jan”, “Feb” etc.(case-sensitive).
  • <year>: In contains the 4 digit year like “2009”
  • <hour>: It contains the hour in 2 digit hour like “07” or “12”.
  • <minute>: Same as hour minutes 2 digit minute like “09” or “55”
  • <second>: Containing the seconds in 2 digit second like “08” or “50”.
  • GMT: All the dates in HTTP will show in Greenwich Mean Time format not in local time format.

Example:

Last-Modified: Tue, 15 Oct 2019 12:45:26 GMT

Advantages:

  • This reduces bandwidth usage and improves the speed of your website.
  • Reduces load on the server.

To check the Last-Modified in action go to Inspect Element -> Network check the request header for Last-Modified like below, Last-Modified is highlighted.

Supported Browsers: The browsers supported by HTTP headers Last-Modified are listed below: