What is Expires HTTP Header

The Expires header tells the cache exactly how long the response may be considered fresh. A response that includes an Expires header may be reused without validation until the expiration time is reached. The Expires header is deprecated in HTTP 1.1 because lots of servers and intermediate devices have un-synchronized on incorrect time.

Important Note: The presence of an Expires header can also turn an otherwise un-cachable response into cachable one. For example the response to POST requests are un-cachable by default but they can be cached if there is an Expires line in the reply header.

These are three ways in which we can set Expires header in Apache HTTP Server

  1. mod_expires: You can use mod_expires module to set both Cache-control and Expires header. BUt problem with this approach is that it does not let you set absolute time say Friday night for expiry of resource, instead you can set expiry time like either access time plus fixed time interval or modification time of a resource plus fixed time interval

    <FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
    ExpiresDefault "access plus 3 month"

    This tells the Apache to set expires time of 3 moths from the time the resource was accessed.
    Since mod_expires sets both cache-control and expires header the cache-control will always take precedence and the value of Expires will be ignored unless the device is HTTP 1.0 and it does not understand cache-control header

  2. mod_header: The mod_headers is a simpler solution which you can use for setting any header on the response

    <FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
    Header append Expires "Fri, 15 Oct 2010 16:49:25 GMT"

    This tells the Apache to set 15th of October as the expiry date for every image, which could be your next release date. But problem with this approach is that you will have to modify the expires date manually after 15th of October or it will set expiry date in the past and which would cause that resource to be un-cachable.

  3. mod_cern_meta: THe mod_cern_meata allows you to define list of HTTP headers in a file and then you can associate that file with resource


Christian Hujer said...

Hello Sunil,

from where did you get the information that the Expires: header in HTTP/1.1 is deprecated? I've checked the following RFCs:

* RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1 (from 1997, obsoleted by RFC 2616)
* RFC 2616 Hypertext Transfer Protocol -- HTTP/1.1 (from 1999, obsolete)
* RFC 2817 Upgrading to TLS Within HTTP/1.1
* RFC 5785 Defining Well-Known Uniform Resource Identifiers (URIs)
* RFC 6266 Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)
* RFC 6585 Additional HTTP Status Codes
* Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
* Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
* Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests
* Hypertext Transfer Protocol (HTTP/1.1): Range Requests
* Hypertext Transfer Protocol (HTTP/1.1): Caching
* Hypertext Transfer Protocol (HTTP/1.1): Authentication

In none of the documents could I find any information that the use of Expires: would be deprecated.

Maybe you can point out the normative specification that claims that Expires: is deprecated?

Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

EG MEDI said...

Egmedi.com is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online.
Cash on Delivery available. Free Home Delivery

Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store