Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting both Expires and Cache-Control: max-age

Can someone clarify this statement about caching.

https://developers.google.com/speed/docs/best-practices/caching says

It is redundant to specify both Expires and Cache-Control: max-age, or to specify both Last-Modified and ETag.

Then later it says

The fingerprinting mechanism allows the server to set the Expires header to exactly one year ahead of the request date; the Last-Modified header to the date the file was last modified; and the Cache-Control: max-age header to 3153600.

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.

like image 493
99miles Avatar asked Sep 30 '12 04:09

99miles


People also ask

What is a good Cache-Control max-age?

It's standard practice to set a Cache-Control: max-age=31536000 on assets which are expected not to change, such as images.

How do I change my Cache-Control max-age?

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.

What's the difference between Cache-Control max-age 0 and no-cache?

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.

How do I set Max Access-Control age?

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.


1 Answers

[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

like image 156
Milos Gavrilov Avatar answered Sep 23 '22 02:09

Milos Gavrilov