Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S-maxage and maxage difference

Tags:

http

caching

I need to understand,use of s-maxage header for caching, are there any example to help me understand in which cases i should use both s-maxage and max-age?

like image 219
Eduard Maralyan Avatar asked Oct 12 '16 07:10

Eduard Maralyan


People also ask

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 Max-age cache?

A cache max-age is a positive integer, expressing a number of seconds. Cache max-ages are passed around as individual integers, because a given cache item can only logically have a single max-age. Examples: 60 means cacheable for 60 seconds. 100 means cacheable for 100 seconds.

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.


1 Answers

As suggested by this comment:

For reverse proxies or other caches on servers, it can actually make sense to have shorter s-maxage than max-age.

A reverse caching proxy will be able to serve the same resource to any number of clients for as long as s-maxage. The load on the proxy will increase with the number of clients, so it may be worth having the proxy's single check (s-maxage) be more frequent than the requests from downstream clients (e.g. browsers) (max-age).

To give a more concrete example: you might want to suggest that a CDN should check regularly (hourly) for an updated resource on an origin server. However, it may be fine for any end user to keep using the response they get for days; users with cold caches will get the updated version.

like image 155
Joe Avatar answered Oct 04 '22 22:10

Joe