CDN Caching vs Browser Caching: How They Work Together
Browser caches eliminate repeat network requests for one user. CDN caches eliminate origin work across many users. A fast website usually needs both layers configured for the content they can safely store.
Key takeaways
- Browser caches are private to a user agent; CDN caches are shared delivery infrastructure.
- Versioned static assets can use long freshness, while personalized responses need private or no-store policies.
- Design cache keys and invalidation before increasing TTLs.
Where each cache sits
The browser HTTP cache sits on the user device. A fresh cached response can be reused with no network request. A CDN cache sits between users and the origin. A hit still crosses the network, but it usually travels to a nearby edge and avoids application and database work.
The layers can cooperate. A CDN may serve the first request and the browser may reuse the response for later navigation. Shared-cache directives can allow the edge to store content longer than the browser when you want frequent client revalidation without repeated origin work.
| Layer | Shared by | Main benefit |
|---|---|---|
| Browser cache | One browser profile | Eliminates repeat network transfer |
| CDN cache | Many users at edge locations | Reduces distance and origin load |
| Origin or application cache | Backend requests | Avoids repeated computation or data access |
Use Cache-Control to express the content policy
max-age controls browser freshness; s-maxage can set a different freshness lifetime for shared caches. public permits shared caching, while private restricts storage to private caches. no-store asks caches not to store the response. Validators such as ETag or Last-Modified support conditional requests after freshness expires.
Do not choose headers by file extension alone. HTML can be public and cacheable; an image download can be private. Base the policy on whether the response varies by user, authorization, cookie, locale, device, or other request properties.
Cache versioned static assets for a long time
Give JavaScript, CSS, font, and image assets content-based names such as app.a83f2.js. When bytes change, the URL changes. That allows a long max-age without serving stale content after a deployment. The HTML references the new asset and old clients can continue using the old immutable URL safely.
Avoid invalidating an entire asset directory on every release. URL versioning creates deterministic cache behavior and preserves the hit ratio for files that did not change.
Cache dynamic public content deliberately
A public article or product list can often tolerate a short shared TTL plus stale-while-revalidate. Even seconds of edge freshness can absorb a traffic spike. Use explicit purge events or surrogate tags when an immediate business update must invalidate related pages.
Never cache a personalized or authenticated response in a shared cache unless the key and policy are designed and tested for that exact variation. A high hit ratio is not worth leaking one user’s content to another.
Control cache keys and verify real behavior
Cookies, query parameters, and request headers can fragment the CDN cache. Forward only the values that actually change the response and normalize parameters where safe. Keep tracking parameters out of the cache key when they do not affect content.
Inspect Age, Cache-Control, Vary, ETag, CDN cache-status headers, and repeated-request timing. Measure hit ratio by content type and edge location. Test stale behavior, purges, deploys, authorization, and error responses before declaring the configuration complete.
Design a two-layer CloudFront caching policy
CloudFront and the browser should receive intentionally different freshness instructions. Versioned assets can stay immutable in both layers for a long time. HTML often needs a short browser lifetime so users discover new releases, while CloudFront can use controlled revalidation or a modest edge lifetime to protect the origin. Personalized and authenticated responses need stricter cache keys or no shared caching at all.
Document cache keys alongside TTLs. Forwarding every cookie, header, and query parameter can fragment the CloudFront cache until hit rate collapses; ignoring a meaningful variant can serve the wrong response. The secure static web architecture is a useful starting point for separating cacheable assets from dynamic API calls.
Release behavior is part of the design. Prefer content-hashed assets and deploy HTML after the referenced files exist. Reserve invalidations for exceptional corrections or paths that cannot be versioned, then verify `Age`, `Cache-Control`, validators, and CloudFront cache status on the public URL. The CloudFront optimization guide goes deeper into origin and cache behavior choices.
- Give immutable assets content hashes and long-lived browser caching.
- Keep cache keys limited to inputs that truly change the response.
- Do not cache private responses in a shared edge cache.
- Measure hit rate and origin load after every policy change.
Common questions
Frequently asked questions
Does a CDN replace browser caching?
No. A CDN shortens network distance and reduces origin work, while a fresh browser cache can eliminate the network request entirely. They solve different parts of delivery.
What should use a one-year cache lifetime?
Content-hashed static assets are good candidates because a changed file receives a new URL. Unversioned HTML and user-specific responses usually need different policies.
What is cache hit ratio?
It is the share of cacheable requests served from the cache rather than fetched from the origin. Interpret it by content type and policy, not as a universal score.
Should CloudFront and the browser use the same TTL?
Not necessarily. Edge and browser caches solve different problems, so HTML may be reusable at CloudFront while still revalidating quickly in the browser.
Go deeper
Tools and related resources
Continue the topic
Related guides
AWS CloudFront Performance: Caching, Compression, and Origins
CloudFront improves performance when it serves useful work close to viewers and shields the origin from repetition. The real optimization target is the cacheable request path, not the existence of a distribution.
TTFB vs LCP: How Server Speed Affects Page Experience
TTFB ends when the first response bytes arrive. LCP ends when the main visible content renders. A fast server is helpful, but it cannot compensate for a late-discovered hero image or a blocked main thread.
Website Image Optimization: Formats, Sizing, and LCP
The best image optimization sends the right bytes for the rendered slot and loads them at the right moment. Format conversion alone cannot fix a 2400-pixel hero delivered to a 390-pixel screen.