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.
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
- HTTP headers | Access-Control-Expose-Headers
- HTTP headers | Access-Control-Request-Headers
- HTTP headers | Access-Control-Allow-Headers.
- HTTP headers | Via
- HTTP Headers | TE
- HTTP headers
- HTTP headers | Age
- HTTP headers | Allow
- HTTP headers | Expect-CT
- HTTP headers | Digest
- HTTP headers | Expect
- HTTP headers | If-Unmodified-Since
- HTTP headers | Set-Cookie
- HTTP headers | Connection
- HTTP headers | Range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.