CDN Cache-Control Header Builder
Build Cache-Control headers for compressed assets — sets max-age, s-maxage, stale-while-revalidate, and Vary: Accept-Encoding correctly for CDN delivery. Choose from 5 asset type presets (content-hashed static assets, HTML pages, public APIs, private APIs) or configure all directives manually. The cdn cache-control header builder generates ready-to-paste config snippets for Nginx, Apache, Cloudflare, AWS CloudFront, Fastly, and Vercel — with real-time warnings for contradictory directive combinations. All generation runs in your browser — no signup required.
CDN Cache-Control Header Builder
Asset Type Preset
Cache Durations
Cache Directives
Vary Headers
Generated Headers
Cache-Control
Cache-Control: max-age=31536000, s-maxage=31536000, stale-if-error=86400, immutable
Vary
Vary: Accept-Encoding
Server / CDN Config Snippet
Nginx snippet
# Nginx — add to your server {} or location {} block
add_header Cache-Control "max-age=31536000, s-maxage=31536000, stale-if-error=86400, immutable";
add_header Vary "Accept-Encoding";
# For compressed assets, also add:
add_header Content-Encoding gzip;Directive Reference
max-age — browser cache TTL in seconds
s-maxage — CDN/shared cache TTL (overrides max-age for CDNs)
stale-while-revalidate — serve stale while fetching fresh in background
stale-if-error — serve stale if origin returns 5xx error
immutable — skip revalidation during max-age (content-hashed assets only)
Vary: Accept-Encoding — required for CDNs to cache compressed variants separately
Why Use Our CDN Cache-Control Header Builder?
Instant Cache-Control Header Generation
Generate correct Cache-Control headers for compressed assets instantly — the cdn cache-control header builder produces ready-to-paste server config snippets for Nginx, Apache, Cloudflare, CloudFront, Fastly, and Vercel with real-time misconfiguration warnings.
Secure CDN Cache-Control Header Builder Online
All header generation runs entirely in your browser. The cdn cache-control header builder never sends your configuration to any server — safe for building headers for internal APIs, authenticated endpoints, and proprietary CDN configurations.
5 Asset Type Presets + Full Custom Mode
Choose from 5 battle-tested presets — content-hashed static assets, versioned assets, HTML pages, public APIs, and private APIs — or configure every directive manually. The cdn cache-control header builder sets max-age, s-maxage, stale-while-revalidate, and Vary correctly for each use case.
100% Free Forever
The cdn cache-control header builder is completely free with no signup, no premium tier, no limits, and no ads. Build Cache-Control headers for unlimited assets and CDN configurations at zero cost, forever.
Common Use Cases for CDN Cache-Control Header Builder
Content-Hashed Static Asset Caching
Build Cache-Control headers for JS, CSS, and image files with content hashes in their filenames — the cdn cache-control header builder generates the correct max-age=31536000, immutable, Vary: Accept-Encoding combination for permanent CDN caching with instant cache busting on deploy.
HTML Page Cache Configuration
Configure Cache-Control for HTML documents that need short CDN caching with stale-while-revalidate for fast delivery. The cdn cache-control header builder sets no-cache with s-maxage and stale-while-revalidate so CDNs serve stale HTML instantly while fetching fresh content in the background.
Public API Response Caching
Generate Cache-Control headers for public JSON API endpoints that benefit from CDN caching. The cdn cache-control header builder sets the correct s-maxage, stale-while-revalidate, and Vary: Accept-Encoding combination so CDNs cache compressed and uncompressed responses separately.
Private / Authenticated Endpoint Headers
Build no-store Cache-Control headers for authenticated API endpoints and user-specific responses. The cdn cache-control header builder ensures private responses are never cached by CDNs or shared caches — preventing sensitive data from being served to the wrong user.
Multi-CDN Configuration
Generate server config snippets for Nginx, Apache, Cloudflare, AWS CloudFront, Fastly, and Vercel from a single set of options. The cdn cache-control header builder eliminates the need to manually translate Cache-Control semantics into each CDN's configuration format.
Stale-While-Revalidate Strategy Planning
Configure stale-while-revalidate and stale-if-error durations for high-availability caching strategies. The cdn cache-control header builder shows exactly how these directives interact with max-age and s-maxage — with warnings for contradictory directive combinations.
Understanding Cache-Control Headers for Compressed Assets
What is a CDN Cache-Control Header Builder?
A CDN cache-control header builder generates the correct Cache-Control and Vary HTTP response headers for assets served through a CDN — ensuring browsers and CDN edge nodes cache responses correctly. For compressed assets (GZIP or Brotli), the Vary: Accept-Encoding header is critical — without it, CDNs may serve a compressed response to a client that does not support compression, causing a decompression error. The cdn cache-control header builder sets max-age (browser TTL), s-maxage (CDN TTL), stale-while-revalidate (background refresh), and stale-if-error (error fallback) correctly for each asset type.
How Our CDN Cache-Control Header Builder Works
- 1Select an asset type preset: Choose from 5 presets — content-hashed static assets, versioned assets, HTML pages, public APIs, or private APIs. Each preset applies the correct combination of directives for that use case. Switch to Custom to configure all options manually.
- 2Adjust durations and directives: Fine-tune max-age, s-maxage, stale-while-revalidate, and stale-if-error using the duration pickers. Toggle cache directives (no-store, no-cache, must-revalidate, immutable) and Vary headers. The cdn cache-control header builder updates the generated headers instantly and shows warnings for contradictory combinations.
- 3Copy the header and server snippet: The generated Cache-Control and Vary header values are shown with one-click copy buttons. Select your CDN or server (Nginx, Apache, Cloudflare, CloudFront, Fastly, Vercel) to get a ready-to-paste configuration snippet.
Key Cache-Control Directives for Compressed Assets
- Vary: Accept-Encoding: The most important header for compressed assets — tells CDNs to store separate cache entries for compressed (gzip/brotli) and uncompressed responses. Without this, a CDN may cache a gzip response and serve it to a client that sent no Accept-Encoding header, causing a broken download.
- s-maxage vs max-age:
s-maxageoverridesmax-agefor shared caches (CDNs, proxies) while leaving the browser TTL unchanged. Uses-maxageto set a longer CDN TTL than the browser TTL — for example,max-age=0, s-maxage=86400means browsers always revalidate but CDNs cache for 24 hours. - stale-while-revalidate: Allows CDNs to serve a stale response immediately while fetching a fresh one in the background. This eliminates the latency spike when a cached response expires — users always get a fast response, and the cache is refreshed asynchronously.
- immutable: Tells browsers not to revalidate the response during its max-age period, even on explicit reload. Only use with content-hashed filenames (e.g.,
app.a1b2c3d4.js) — if the content changes, the filename must change to bust the cache.
Common Cache-Control Mistakes to Avoid
The most common mistake is setting Cache-Control: max-age=31536000 without Vary: Accept-Encoding on compressed assets — CDNs will cache only one variant and may serve the wrong one. Another common error is using immutable without content-hashed filenames — if the file changes but the URL stays the same, browsers will serve the stale cached version indefinitely. The cdn cache-control header builder detects these issues and shows warnings in real time. Always test your Cache-Control headers with curl -Iand verify CDN behavior with your CDN's cache inspector before deploying to production.
Related Tools
JSON Key Shortener
Shorten verbose JSON keys to single letters or abbreviated forms — shows size reduction and provides a downloadable key mapping file for restoration. Free online JSON key shortener.
JSON vs MessagePack Size Comparison
Compare JSON byte size vs MessagePack encoding for any payload — shows exact savings, type-by-type breakdown, and MessagePack hex preview. Free online JSON vs MessagePack comparison.
String Decompressor (GZIP/LZ)
Decompress GZIP+Base64, DEFLATE+Base64, and LZ-String compressed payloads back to readable text — supports all three LZ-String variants. Free online string decompressor.
ZIP File Extractor
Extract files from any ZIP archive client-side — browse contents, preview text files, download individual files or all at once. Free online ZIP extractor, no signup required.
Frequently Asked Questions About CDN Cache-Control Header Builder
A cdn cache-control header builder generates correct Cache-Control and Vary HTTP response headers for assets served through a CDN — ensuring browsers and CDN edge nodes cache responses correctly. Our free cdn cache-control header builder online produces ready-to-paste server config snippets for Nginx, Apache, Cloudflare, CloudFront, Fastly, and Vercel. All generation runs in your browser with no signup required.
Without Vary: Accept-Encoding, a CDN may cache a gzip-compressed response and serve it to a client that sent no Accept-Encoding header — causing a broken download or garbled content. The Vary header tells CDNs to store separate cache entries for compressed and uncompressed variants of the same URL.
Yes. All header generation runs entirely in your browser using JavaScript. No configuration data is sent to any server, stored remotely, or transmitted over the network — safe for building headers for internal APIs and proprietary CDN configurations.
Yes — 100% free, forever. No signup, no account, no premium tier, no limits, and no ads. Build Cache-Control headers for unlimited assets and CDN configurations at zero cost.
max-age sets the browser cache TTL — how long the browser caches the response before revalidating. s-maxage overrides max-age for shared caches (CDNs, proxies) while leaving the browser TTL unchanged. Use s-maxage to set a longer CDN TTL than the browser TTL — for example, max-age=0, s-maxage=86400 means browsers always revalidate but CDNs cache for 24 hours.
Use immutable only with content-hashed filenames (e.g., app.a1b2c3d4.js) and max-age=31536000. It tells browsers not to revalidate the response during its max-age period, even on explicit reload. If the content changes, the filename must change to bust the cache — never use immutable with non-hashed URLs.
stale-while-revalidate allows CDNs to serve a stale response immediately while fetching a fresh one in the background. This eliminates the latency spike when a cached response expires — users always get a fast response, and the cache is refreshed asynchronously. Use it for HTML pages and API responses where a slightly stale response is acceptable.
Use no-store for truly sensitive data (authentication tokens, personal data) — it prevents any caching, including in the browser. Use no-cache for responses that can be cached but must always be revalidated before serving — the browser stores the response but checks with the server on every request. For most private APIs, no-store is the safer choice.
Test with curl: curl -I https://yoursite.com/assets/app.js. Look for Cache-Control and Vary headers in the response. For CDN behavior, use your CDN's cache inspector (Cloudflare: CF-Cache-Status header, CloudFront: X-Cache header). Always test both compressed and uncompressed requests to verify Vary: Accept-Encoding is working correctly.