HomeGuidesUnderstanding HTTP Cache-Control and ETags: Web Performance & Cache Invalidation
Backend & Web Architecture7 min readUpdated 2026-11-07

Understanding HTTP Cache-Control and ETags: Web Performance & Cache Invalidation

Master modern HTTP caching headers. Learn Cache-Control directives (max-age, immutable, stale-while-revalidate), conditional requests, and 304 Not Modified handshakes.

Need to do this immediately?

Use our free, private client-side browser tool with zero installation.

Launch API & HTTP Request Builder
The fastest HTTP request is the request that never travels across the network. Properly architected HTTP cache headers reduce origin server load by up to 90%, slash cloud egress bills, and deliver near-instantaneous page loads for returning visitors.

Anatomy of Modern Cache-Control Directives

Cache-Control: public, max-age=31536000, immutable instructs browsers and intermediate CDNs to cache hashed static assets (JS chunks, CSS stylesheets) for a full year without ever querying the server again.

For dynamic HTML or API endpoints, stale-while-revalidate=86400 serves cached content instantaneously while asynchronously fetching fresh updates in the background.

Pro Tip:Never use Cache-Control: max-age=31536000 on assets that lack content-hash filenames (e.g. index.html or logo.png).

ETags and Conditional 304 Handshakes

An Entity Tag (ETag) is a unique cryptographic digest (such as a truncated SHA-256 hash or file modification time) assigned by the server to a specific version of a resource.

When the local browser cache expires, the client sends If-None-Match: "xyz123". If the resource remains unchanged, the server responds with a lightweight HTTP 304 Not Modified header with zero payload body.

Step-by-Step Tutorial

1

Audit Response Headers in DevTools

Open Chrome DevTools > Network tab. Inspect Cache-Control, Age, ETag, and CF-Cache-Status headers.

2

Segment Static from Dynamic Routes

Apply 1-year immutable caching to /_next/static/* and strict no-cache, must-revalidate to user-specific API routes.

3

Validate 304 Not Modified Handshake

Execute curl -I --header 'If-None-Match: "etag-value"' https://yourdomain.com/asset to verify status code 304 response.

Ready to Try It Yourself?

DocSwift processes everything directly on your device. Fast, safe, and completely free forever.

How helpful was this guide?

Rated 4.9 / 5 by 3,420+ users worldwide

Share with Colleagues & Friends

Help others protect their document privacy

Frequently Asked Questions

What is the difference between no-cache and no-store?

no-cache permits browsers to store the file, but forces revalidation with the server before every use. no-store completely forbids saving the file to disk or memory.

Does Cloudflare CDN respect origin Cache-Control headers?

Yes, by default Cloudflare respects origin Cache-Control directives unless overridden by Page Rules or Cache Rules.