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.
It's standard practice to set a Cache-Control: max-age=31536000 on assets which are expected not to change, such as images.
Cache-Control: max-age=<seconds> This directive tells the browser or intermediary cache how long the response can be used from the time it was requested. A max-age of 3600 means the response can be used for the next 60 minutes before it needs to fetch a new response from the origin server.
When max-age=0 is used, the browser will use the last version when viewing a resource on a back/forward press. If no-cache is used, the resource will be refetched.
To check this Access-Control-Max-Age in action, go to Inspect Element -> Network check the response header for Access-Control-Max-Age like below, Access-Control-Max-Age is highlighted you can see.
[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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With