MicroPosts
- HTTP cache cookbook
Examples:
- Fingerprinted URLs
- Want: allow intermediate caches (not only browser) to cache for a year and after that revalidate with ETag
- Use:
Cache-Control: public, max-age=31536000
and configureETag
header in server's responses
- Mutable content
- Want: Always revalidate with ETag
- Use:
Cache-Control:
no-cacheAND configure
ETag`
What's the difference between
no-cache
vsmust-revalidate
+max-age
?no-cache
requires client to ALWAYS check if content is fresh (e.g., withETag
orLast-Modified
)must-revalidate
+max-age
allows the cache to serve cached content untilmax-age
is reached
Why using
Cache-Control: must-revalidate, max-age=600
is a bad idea for mutable content?If that Url serves an Html that fetches additional assets (e.g., Js, Css) with the same cache strategy, the cache may load Html and Css and the server may load Js which refers to the newer (not cached) Html and Css.
Source: Prevent unnecessary network requests with the HTTP Cache
- Fingerprinted URLs