HTTP headers | expires

The HTTP Expires header is a response-type header, the fundamental way of controlling the caches present. The expire header contains the date and time which denotes the period where the object can stay alive. Once the period expires, the object becomes stale. Almost every client support expire headers. The expire headers are usually ignored if a cache-control header is present with a max-age directive. The users need not press the reload button in order to get a live object. Once the time expires the caches take control over the pages. Web servers allow clients to set the expire headers in multiple ways. The two most common ways may include:

  • Last access time: It sets the expire time-based on the final time the client accessed the object.
  • Last modification time: It denotes the last time the document was changed on the server.

Syntax:

Expires: <http-date>

Directives: The HTTP Expires header accepts a single directive mentioned above and described below:



  • <http-date>: This directive contains the date time information of the retirement.

Below example will illustrate the HTTP Expires header:

Example: In this example, the object is set with an expiry date and time. It will enable the caches to know when to get a fresh copy of the object. The users need not press the reload button in order to get a live object. Once the time expires the caches take control over the pages.

Expires: Mon,11 Nov 2019 08:36:00 GMT

To check this Expires in action go to Inspect Element -> Network check the response header for Expires like below, Expires is highlighted you can see.

Note: The time denoted in HTTP date should always hold Greenwich Meridian Time(GMT) and not local time.

Supported Browsers: The browsers are compatible with HTTP Expires header are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.