Why does API return 304 Not Modified instead of JSON?
Per Wikipedia: “HTTP caching lets clients and intermediaries store responses and revalidate via ETag, Last-Modified, Cache-Control and 304.”
Caching is leftovers — second visit eats from fridge if still fresh, else asks if still good.
- Server sends Cache-Control and ETag
- Client caches response
- Next request sends If-None-Match
- Server returns 304 if unchanged
- Client uses cached body
- ETag strong validator
- Cache-Control max-age governs freshness
- 304 saves bandwidth
Cache-Control: max-age=60
ETag: "abc"- Built from: HTTP Headers — caching via headers
- Related: HTTP Status Codes — 304 code
- Builds into: HTTP Request Response Cycle — caching short-circuits cycle
- Related: Statelessness — caching keeps stateless
- Caching with auth — private vs public
- Stale while revalidate confusion