The Expires
header Expires
mostly deprecated since HTTP 1.1; Use Cache-Control: max-age
instead.
Make sure you enable Last-Modified
.
This is optional, but you can also specify Cache-Control: must-revalidate
so that intermediate proxies do not deliver potentially stale content.
You do not need to install ETag
.
Request example:
GET http://localhost/images/logo.png HTTP/1.1 Accept: image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5 Referer: http://localhost/default.aspx Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Accept-Encoding: gzip, deflate Host: localhost Connection: Keep-Alive
The response includes the requested content:
HTTP/1.1 200 OK Cache-Control: max-age=10 Content-Type: image/png Last-Modified: Sat, 21 Feb 2009 11:28:18 GMT Accept-Ranges: bytes Date: Sun, 18 Dec 2011 05:48:34 GMT Content-Length: 2245
Requests made before the 10 second timeout are resolved from the cache, without an HTTP request. After the timeout:
GET http://localhost/images/logo.png HTTP/1.1 Accept: image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5 Referer: http://localhost/default.aspx Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Accept-Encoding: gzip, deflate Connection: Keep-Alive If-Modified-Since: Sat, 21 Feb 2009 11:28:18 GMT Host: localhost
The answer is only headers, without content:
HTTP/1.1 304 Not Modified Cache-Control: max-age=10 Last-Modified: Sat, 21 Feb 2009 11:28:18 GMT Accept-Ranges: bytes Date: Sun, 18 Dec 2011 05:49:04 GMT
Subsequent requests are again resolved from the browser cache before the specified cache expiration date.