When it comes to the HTTP
Cache-Control response header, I try to follow Jake Archibald’s advice, which revolves around two main patterns: (1) using a long
max-age (e.g., 1 year) for content that never changes (and whose URL is versioned), and (2) using
no-cache for content that can change (the browser will always check with the server if a newer version is available before using the cached content).
In addition to
no-cache, there are a few other
Cache-Control directives that can be useful in some scenarios.
no-storedirective instructs the browser to not store the response in the cache at all. This can be useful for responses that contain sensitive or time-critical information.
immutabledirective tells the browser that the response will not change over time, which effectively means that the browser never has to check with the server if a newer version is available.
Cache-Control: max-age=31536000, immutable
When the user manually refreshes the page, the browser checks with the server even if the cached content is still “fresh.” In this situation,
immutablecan help prevent unnecessary checks for content that never changes.
See Harry Roberts’s article “Cache-Control for Civilians” for more details on the different
This content was originally published on https://webplatform.news.