← Blog

The best `Cache-Control` strategy

· 1727 days ago · 0 views

A wild tweet from appeared on my timeline:

I can see the @mjackson’s point there: A local cache copy is better than nothing, and caching it for a while (in this case, one minute) is okay for most static web assets scenarios.

However, what happens when your content tends to change, even if it is done in an infrequent way?

In that case, the strategy could be complemented very well must-revalidate:

Cache-Control: max-age=60, stale-while-revalidate=0

In that way, the cached copy will always be used while the data is being validated in the background, saving the user to be faced with a cache MISS and refreshing the cache copy as soon as possible.

Bibliography