Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expires vs max-age, which one takes priority if both are declared in a HTTP response?

If a HTTP response that returns both Expires and max-age indications which one is used?

Cache-Control: max-age=3600 Expires: Tue, 15 May 2008 07:19:00 GMT 

Considering that each one refers to a different point in time.

like image 573
vtortola Avatar asked Sep 25 '11 22:09

vtortola


People also ask

What is the difference between expires and max-age?

Quick Answer:Expires sets an expiry date for when a cookie gets deleted. Max-age sets the time in seconds for when a cookie will be deleted (use this, it's no longer 2009) Internet Explorer (ie6, ie7, and ie8) does not support “max-age”, while (mostly) all browsers support expires.

What happens for an HTTP response if it has both the Expires and Cache-Control headers set?

If both Expires and max-age are set max-age will take precedence. While Cache-Control and Expires tells the browser when to next retrieve the resource from the network a few additional headers specify how to retrieve the resource from the network. These types of requests are known as conditional requests.

What is Max-age in HTTP header?

max-age. The max-age directive states the maximum amount of time in seconds that fetched responses are allowed to be used again (from the time when a request is made). For instance, max-age=90 indicates that an asset can be reused (remains in the browser cache) for the next 90 seconds.

Which response header will tell the client that the response is cached for one minute?

Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).


1 Answers

See this answer:

Difference between three .htaccess expire rules

If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive. This rule allows an origin server to provide, for a given response, a longer expiration time to an HTTP/1.1 (or later) cache than to an HTTP/1.0 cache. This might be useful if certain HTTP/1.0 caches improperly calculate ages or expiration times, perhaps due to desynchronized clocks.

like image 187
Peter O. Avatar answered Oct 11 '22 13:10

Peter O.