Notes on HTTP caching
I look this up every time, so here's the note I keep needing.
Two kinds of caching
| Kind | Behavior | Headers |
|---|---|---|
| Fresh | no request at all | Cache-Control: max-age=…, Expires |
| Conditional | asks the server if it changed | ETag / If-None-Match, Last-Modified / If-Modified-Since |
In practice
- Fingerprinted assets:
max-age=31536000, immutable - HTML:
no-cache(revalidate every time), or a very short max-age - Only
no-storemeans truly no caching;no-cachemeans revalidate
Biggest misconception:
no-cachedoes not mean "don't cache".