Skip to content

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.

Rajesh DhimanFebruary 08, 2026~24 min
On this page

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-Match enables 304 responses.
  • Use s-maxage for CDN/shared caches.
  • Cache static assets aggressively with fingerprinting.

1) The 3 layers of caching (mental model)

  1. Browser cache (your device)
  2. CDN / edge cache (near user)
  3. 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 cache
  • no-store — don’t store at all
  • no-cache — can store but must revalidate
  • s-maxage — max-age for shared caches
  • stale-while-revalidate — serve stale while fetching fresh

Example for static assets:

Cache-Control: public, max-age=31536000, immutable

Example for HTML pages (often):

Cache-Control: no-cache

3) Validation caching: ETag + If-None-Match

ETag is a version identifier for a resource.

Flow:

  1. Server responds with ETag: "abc"
  2. Next request sends If-None-Match: "abc"
  3. 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: private for user-specific responses
  • Vary: Authorization or Vary: Cookie when 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.
Companion Book

Looking for structured, offline interview prep?

Free online lessons • Portable Amazon Kindle / Paperback

JavaScript Interview Guide cover
Recommended for Core JS Rounds

JavaScript Interview Guide

By Rajesh Dhiman

Deep dive into the Event Loop, microtask draining, closures, prototypal inheritance, and asynchronous execution patterns.

View on Amazon ↗Kindle & Paperback
Frontend Interview Guide (2025 Edition) cover
Recommended for React & Frontend Rounds

Frontend Interview Guide (2025 Edition)

By Rajesh Dhiman

Comprehensive preparation covering React internals, Web Performance, CSS architecture, and system design questions.

View on Amazon ↗Kindle & Paperback

Note: All lessons on Frontend Interview remain completely free to read online. As an Amazon Associate, we may earn from qualifying purchases.

RD

Written by Rajesh Dhiman

Authored by Rajesh Dhiman and engineered at Eunix Tech. Focused on deep-dive frontend engineering, JavaScript runtime internals, React architecture, and web performance.