views:

30

answers:

1

When using Cache-Control and Expires header so that a page won't expire in 10 years:

Cache-Control: max-age=315360000
Expires: Sun, 19 Jul 2020 18:06:32 GMT

will using line 1 have identical result as line 2?

<link href="/public/doc.css?v=128" ... >

<link href="/public/doc_v128.css" ... >

I was thinking maybe some browser will take the ?v=128 as a somewhat more dynamic content and reload it before the 10 year expiration?

Otherwise, both files will expire in 10 years and when there is changes to the CSS, the 128 can be updated to 129 and it will be loaded for sure and have a brand new 10 year expiration date?

(the same goes for javascript .js files)

+1  A: 

Using a changing value in the querystring may work against you. According to Google's Page Speed Optimize caching Performance Best Practice:

Don't include a query string in the URL for static resources

Most proxies, most notably Squid up through version 3.0, do not cache resources with a "?" in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.

Also, you may want to reconsider 10 years. According to the Header Field Definitions > Expires section of RFC 2616, one year is the max.

To mark a response as "never expires," an origin server sends an Expires date approximately one year from the time the response is sent. HTTP/1.1 servers SHOULD NOT send Expires dates more than one year in the future.

Kevin Hakanson
why the "Should not"? For example, in the book High Performance Web Sites by a chief tech person in Yahoo, it describes a usage to set the expiration to 10 years, by using both `Expires` header and `Cache-Control max-age`
動靜能量
(the name of the author is Steve Sounders)
動靜能量
"Given the frequency with which users clear their cache and fill their cache, setting an expiration date one year or ten years in the future might not make much difference" - http://developer.yahoo.net/blog/archives/2007/05/high_performanc_2.html
Kevin Hakanson

related questions