Browser Cache vs CDN Cache: Key Differences

Understand the fundamental differences between browser caches and CDN caches, how Cache-Control directives affect each differently, and how to optimize for both.

Advanced

Detailed Explanation

Two Layers of Caching

Modern web applications benefit from two distinct caching layers, each with its own behavior and Cache-Control interpretation.

Browser Cache (Private Cache)

The browser cache is local to the user's device. It stores responses for that specific user only.

Characteristics:

  • Controlled by max-age and private
  • Cannot be purged remotely
  • Limited by disk space (typically 50–500 MB)
  • Shared across tabs and windows for the same domain
  • Survives browser restarts (disk cache)

CDN Cache (Shared Cache)

The CDN cache sits between users and your origin server. It stores responses at edge locations worldwide.

Characteristics:

  • Controlled by s-maxage, public, and CDN-specific headers
  • Can be purged instantly via API
  • Large capacity (terabytes per edge node)
  • Shared across ALL users
  • Volatile (restarted during deployments)

How Directives Affect Each

Directive Browser CDN
max-age=N Caches for N seconds Caches for N seconds (if no s-maxage)
s-maxage=N Ignored Caches for N seconds
public No effect Allowed to cache
private Caches normally Must NOT cache
no-cache Must revalidate Must revalidate
no-store Must not cache Must not cache
immutable Skips reload revalidation Varies by CDN

Layered Caching Strategy

The optimal strategy uses different durations for each layer:

Cache-Control: public, max-age=60, s-maxage=3600
  • CDN: Caches for 1 hour (can be purged if needed)
  • Browser: Caches for 1 minute only

This gives the CDN maximum efficiency while keeping the browser relatively fresh. The asymmetry works because CDNs support instant purge but browser caches don't.

Request Flow

  1. User requests a page
  2. Browser cache check: Is there a fresh cached version? → Serve it (fastest)
  3. CDN cache check: Is there a fresh cached version? → Serve it (fast)
  4. Origin server: Generate and return the response (slowest)

Debugging Cache Behavior

Check response headers to understand which cache served the request:

  • X-Cache: HIT — CDN cache hit
  • CF-Cache-Status: HIT — Cloudflare cache hit
  • Age: 120 — Response has been in CDN cache for 120 seconds
  • Chrome DevTools "Size" column shows "(disk cache)" or "(memory cache)" for browser hits

Use Case

A global SaaS application serves users across 6 continents. The CDN has edge nodes in 200+ cities. With 'public, max-age=0, s-maxage=300', API responses are cached at the nearest edge node for 5 minutes. A user in Tokyo gets a 20ms response from the Tokyo edge instead of a 200ms response from the US-East origin. The browser's max-age=0 ensures the user always gets the latest data from the edge, while s-maxage=300 keeps origin load minimal.

Try It — Cache-Control Builder

Open full tool