Caching
Use HTTP caching headers. The server controls cache policy; the client honors it.
Immutable assets (versioned JS/CSS/images):
Cache-Control: public, max-age=31536000, immutable
Dynamic but cacheable (API responses):
Cache-Control: private, max-age=60
MUST NOT cache (sensitive data, mutations):
Cache-Control: no-store
Conditional requests — use ETags to avoid re-downloading unchanged data:
- Server sends
ETag: "abc123" - Client revalidates with
If-None-Match: "abc123" - Server responds 304 Not Modified (no body) or 200 with new data
Client-side invalidation:
- After mutations (POST/PUT/DELETE), related cache entries MUST be invalidated
- Stale-while-revalidate: serve cached data immediately, refresh in background
- Framework support: React Query, SWR, Apollo Client all handle this natively
References: