HTTP Caching for Frontend: Cache-Control, ETag, and Practical Strategies
A deep, interview-ready guide to HTTP caching: Cache-Control directives, ETag/If-None-Match, Last-Modified, CDN caching, and how frontend apps should leverage caching safely.
Frontend Interview Team
February 08, 2026
Caching is one of the biggest performance levers. Interviews ask about it because it’s easy to talk about but hard to get right.
This guide focuses on the practical pieces frontend engineers should know.
30‑second interview answer
HTTP caching is controlled mainly by Cache-Control plus validators like ETag/If-None-Match and Last-Modified/If-Modified-Since. You choose between freshness caching (serve from cache until max-age) and revalidation (use validators to get 304). Use long cache for versioned static assets, and revalidate or no-store for user-specific/sensitive data.
Key points
max-age= freshness;no-cache= store but revalidate;no-store= don’t store.ETag+If-None-Matchenables 304 responses.- Use
s-maxagefor CDN/shared caches. - Cache static assets aggressively with fingerprinting.
1) The 3 layers of caching (mental model)
- Browser cache (your device)
- CDN / edge cache (near user)
- Server / app cache (backend)
HTTP headers control (1) and (2) heavily.
2) Cache-Control (the main header)
Common directives:
max-age=...— how long it can be used (seconds)public— can be cached by shared caches (CDNs)private— only browser cacheno-store— don’t store at allno-cache— can store but must revalidates-maxage— max-age for shared cachesstale-while-revalidate— serve stale while fetching fresh
Example for static assets:
Cache-Control: public, max-age=31536000, immutableExample for HTML pages (often):
Cache-Control: no-cache3) Validation caching: ETag + If-None-Match
ETag is a version identifier for a resource.
Flow:
- Server responds with
ETag: "abc" - Next request sends
If-None-Match: "abc" - If unchanged → server returns
304 Not Modified
This saves bandwidth.
4) Last-Modified + If-Modified-Since
Similar idea, based on timestamps. Less precise than ETag.
5) CDN caching vs user-specific data
A classic production bug is caching personalized responses.
Rule:
- Never cache user-specific API responses as public.
Use:
Cache-Control: privatefor user-specific responsesVary: AuthorizationorVary: Cookiewhen needed
6) Frontend strategy: what to cache
Cache aggressively
- JS/CSS bundles with content hashes
- images
- fonts
Be careful
- HTML shell (depends on SSR/ISR strategy)
- API responses (depends on privacy)
In SPAs, app-level caching often uses:
- React Query / SWR
- service worker caches
7) Interview Q&A
Q: no-cache vs no-store?
no-store: don’t store at all.no-cache: may store but must revalidate.
Q: What does immutable mean?
- resource won’t change during max-age (good for hashed assets).
Q: Why use ETag?
- validation caching to return 304 and save bandwidth.
Summary checklist
- I can explain freshness vs validation caching.
- I can explain no-store vs no-cache.
- I know how ETag enables 304.
- I can describe caching strategy for hashed assets.
Summary
- Cache-Control is the main tool.
- ETag enables 304 validation caching.
- Cache static assets aggressively (hashed + immutable).
- Never accidentally cache personalized responses at CDN.