The resources that work best with caching are static immutable files whose contents never change. And for resources that do change, it is a common best practice to change the URL each time the content changes, so that the URL unit can be cached for a longer period.
As an example, consider the following HTML:
<link rel="stylesheet" href="build.css" />
So the HTML above makes it difficult to cache
# version in filename
# version in query
# hash in filename
# hash in query
Since the cache distinguishes resources from one another based on their URLs, the cache will not be reused again if the URL changes when a resource is updated.
<link rel="stylesheet" href="build.v123.css" />
max-age be set to? The QPACK specification provides an answer to that question.
QPACK is a standard for compressing HTTP header fields, with tables of commonly-used field values defined.
Some commonly-used cache-header values are shown below.
36 cache-control max-age=0
37 cache-control max-age=604800
38 cache-control max-age=2592000
39 cache-control no-cache
40 cache-control no-store
41 cache-control public, max-age=31536000
If you select one of those numbered options, you can compress values in 1 byte when transferred via HTTP3.
41 are for periods of one week, one month, and one year.
Because the cache removes old entries when new entries are saved, the probability that a stored response still exists after one week is not that high — even if
max-age is set to 1 week. Therefore, in practice, it does not make much difference which one you choose.
Note that number
41 has the longest
max-age (1 year), but with
public value has the effect of making the response storable even if the
Authorization header is present.
public directive should only be used if there is a need to store the response when the
Authorization header is set. It is not required otherwise, because a response will be stored in the shared cache as long as
max-age is given.
So if the response is personalized with basic authentication, the presence of
public may cause problems. If you are concerned about that, you can choose the second-longest value,
38 (1 month).
# response for bundle.v123.js
# If you never personalize responses via Authorization
# If you can't be certain