Reputation: 11212
Can someone clarify this statement about caching.
https://developers.google.com/speed/docs/best-practices/caching says
It is redundant to specify both
Expires
andCache-Control: max-age
, or to specify bothLast-Modified
andETag
.
Then later it says
The fingerprinting mechanism allows the server to set the
Expires
header to exactly one year ahead of the request date; theLast-Modified
header to the date the file was last modified; and theCache-Control: max-age
header to3153600
.
This latter statement goes against the prior -- about not setting both the Expires
and Cache-Control
.
Is the first statement the norm, and the second an exception? Or is this doc simply going against it's own recommendations? What's suggested?
Thanks.
Upvotes: 5
Views: 5570
Reputation: 436
[Cache-Control:max-age] and [Expires] in Http are doing the same thing and that is a reason why they are redundant. But there are still some big differences between them, [Cache-Control] is http/1.1 standard and Expires is http/1.0. If client browser does not support http/1.1 Cache-Control will be ignored, and that is a reason why you can use them both.
If you use them both, [Cache-Control] has priority. More information you can find here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3
Upvotes: 13
Reputation: 1146
Well...
I can tell you that the first statement is correct, because you really don't need to specify both [Expires] and [Max-Age] headers since they both do the same thing (setting max period for Caching)
Same also goes for [Last Modify] and [Etag], as both address freshness.
I agree that there seems to be some confusion, as the example they give later on uses both [Expires] and [Max-Age] headers.
At first glance this looks like some kind of documentation error.
Still, You need to remember that , while you don't have to use both [Expires] and [Max-Age], you surely can use them both, just as long as they point to the same date - like in the example they provide.
To summarize:
The first statement talks about redundancy (which is not necessary "bad", and can be "just" wasteful). The example they give later on, while not optimized, will cause no issues.
As long as you don't set different expiration dates using the two headers, you`ll be just fine.
Upvotes: 2