Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it make sense to have max-age and s-maxage in the Cache-Control HTTP header?

Considering that max-age applies to all the caches, and s-maxage only applies to shared caches (proxy and gateway cache)....

Does it make sense to use both directives in a non-expirable and public page?

Controller pseudo-code:

w = Response(); w.setPublic(); w.setMaxAge("1 year"); w.setShareMaxAge("1 year");  return w; 
like image 389
unairoldan Avatar asked Apr 12 '13 12:04

unairoldan


People also ask

What is Max-age in Cache-Control?

max-age. The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated. Cache-Control: max-age=604800. Indicates that caches can store this response and reuse it for subsequent requests while it's fresh.

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.

What is S Maxage?

s-maxage=seconds — Indicates that in shared caches, the maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header field. The s-maxage directive also implies the semantics of the proxy-revalidate response directive. Browsers ignore s-maxage .

What is Cache-Control HTTP header?

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

From HTTP Header Field Definitions:

14.9.3 Modifications of the Basic Expiration Mechanism

...

s-maxage

If a response includes an s-maxage directive, then for a shared cache (but not for a private cache), the maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header.

...

Note, "overrides". So, it would only make sense if you intend to specify a different maximum age for shared caches as compared to max-age, which would be used by end users.

In your particular example, they're the same, so specifying s-maxage is just unnecessary.

like image 86
BalusC Avatar answered Oct 11 '22 20:10

BalusC