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
- 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"
</FilesMatch>
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 - 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"
</FilesMatch>
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. - 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
Hello Sunil,
ReplyDeletefrom 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?
Thanks for info
ReplyDeleteWeb Design Company in Bangalore
Website development in Bangalore