Build a Cache-Control response header when you need to define whether browsers or shared caches may store a response, how long it stays fresh, and what should happen after it becomes stale. Use the FreeProKit Cache-Control Header Builder as a starting point for static assets, HTML pages, API responses, or CDN policies, then verify the generated value against your application and cache architecture. Because caching directives interact, always check the final header rather than assuming directives such as no-cache, no-store, max-age, and s-maxage are interchangeable.
What Is a Cache-Control Header?
Cache-Control is an HTTP header used to send caching instructions along the request and response chain. On responses, it can tell browsers and shared caches such as CDNs whether a response may be stored, how long it remains fresh, whether stale content can be reused, and when revalidation is required.
A Cache-Control Header Builder helps turn caching intent into a correctly formatted header value. The important part is not just syntax: you need to understand which cache layer each directive affects and how multiple directives interact.
How to Use the Cache-Control Header Builder
- Open the Cache-Control Header Builder in a JavaScript-enabled browser.
- Use the directive and freshness controls that appear in the live FreeProKit workspace. The crawler could not verify the exact control list because the direct page was temporarily rate-limited.
- Decide first whether the response is public, private, or should not be stored at all.
- Set any freshness lifetime required for browsers and, if applicable, a separate lifetime for shared caches.
- Add revalidation, immutable, stale-response, or transformation directives only when they match the resource and cache architecture.
- Review the generated header, copy it, place it in the appropriate server/CDN/application configuration, and verify the deployed response headers.
Core Cache-Control Directives
|
Directive |
What it means |
Typical use |
|
max-age=N |
Response remains fresh for N seconds from generation. |
Browser/private cache freshness; also applies to shared caches unless overridden. |
|
s-maxage=N |
Sets freshness for shared caches and overrides max-age/Expires there. |
CDNs and shared proxy caches. |
|
public |
Allows a response to be stored in a shared cache when otherwise permitted. |
Public cacheable resources. |
|
private |
Restricts storage to private caches such as a browser cache. |
User-specific or personalized responses. |
|
no-cache |
Allows storage but requires validation with the origin before reuse. |
HTML or data that should be checked before reuse. |
|
no-store |
Tells caches not to store the response. |
Highly sensitive responses or data that must not be retained. |
|
must-revalidate |
Once stale, a cached response must be revalidated before reuse. |
Policies that must not serve stale content. |
|
proxy-revalidate |
Like must-revalidate, but only for shared caches. |
Shared-cache-specific revalidation. |
|
immutable |
Indicates the representation will not change while fresh. |
Versioned or content-hashed static assets. |
|
no-transform |
Asks intermediaries not to modify the response body. |
Content that should not be transformed by proxies/intermediaries. |
no-cache vs. no-store
The names are easy to confuse. no-cache does not mean “do not cache.” It allows a response to be stored, but the cache must validate it with the origin before reuse. This can work efficiently with validators such as ETag or Last-Modified because an unchanged response can often be confirmed without downloading the full body again.
no-store is the directive for preventing storage. Use it when the response should not be retained by private or shared caches. It is more restrictive and should not be added automatically to every dynamic page.
|
Key distinction Use no-cache when storage is acceptable but reuse should be validated. Use no-store when the response should not be stored at all. |
max-age vs. s-maxage
max-age defines how long a response is considered fresh. s-maxage is specifically for shared caches such as CDNs and proxies; private browser caches ignore it. When s-maxage is present, it takes precedence over max-age and Expires in shared caches.
|
Cache-Control: public, max-age=300, s-maxage=3600 |
In this example, a browser can treat the response as fresh for five minutes, while a shared cache can treat it as fresh for one hour. Whether a CDN actually follows that policy can still depend on the CDN’s own configuration, cache key rules, and platform-specific overrides.
Freshness, Staleness, and Revalidation
A cached response is fresh while its freshness lifetime has not expired. Once that lifetime ends, it becomes stale. A stale response is not automatically deleted; the cache may need to revalidate it or may be allowed to reuse it under specific directives.
Revalidation usually works through conditional requests. If an ETag is available, the cache can send If-None-Match. If Last-Modified is available, it can send If-Modified-Since. When the content has not changed, the origin can respond with 304 Not Modified instead of sending the full representation again.
stale-while-revalidate and stale-if-error
stale-while-revalidate allows a cache to serve a stale response for a defined period while it revalidates that response in the background. This can hide revalidation latency from users when the cache implementation supports the directive.
stale-if-error allows a stale response to be reused for a defined period when an upstream error occurs. RFC 5861 defines these two extensions as separate controls, so they can be used independently.
|
Cache-Control: public, max-age=600, stale-while-revalidate=60, stale-if-error=86400 |
This example is fresh for 10 minutes. After that, supported caches may serve stale content for up to 60 seconds while revalidating, and may reuse stale content for up to one day when an eligible upstream error occurs.
When to Use immutable
immutable tells clients that the representation will not change during its freshness lifetime. It is most useful for static resources whose URL changes whenever the file content changes, such as content-hashed JavaScript, CSS, fonts, or images.
|
Cache-Control: public, max-age=31536000, immutable |
The critical part is the URL strategy. If /app.js can change while the URL stays the same, a one-year immutable policy can trap users on an old version. If the filename changes with the content, such as app.a1b2c3.js, a long fresh lifetime is much safer.
Caching HTML Pages
HTML often changes while keeping the same URL, so a long immutable lifetime is usually inappropriate. A revalidation-oriented policy can let the browser keep a copy but check whether it is still current before reuse.
|
Cache-Control: no-cache |
For this pattern to be efficient, configure validators such as ETag or Last-Modified where appropriate. The cache can then revalidate and receive a 304 response when the HTML has not changed.
Caching Private or Personalized Responses
Personalized content deserves special attention because a shared cache must not accidentally reuse one user’s representation for another user. The private directive restricts storage to a private cache such as the user’s browser.
|
Cache-Control: private, no-cache |
This example allows browser storage but requires validation before reuse. If the response is highly sensitive and should not be stored at all, no-store is the more restrictive choice.
Cache-Control and Expires
Expires is an older HTTP freshness header that uses an absolute date. Cache-Control provides more flexible directives and is normally the primary mechanism for modern caching policy. Where both are present, Cache-Control freshness directives take precedence according to HTTP caching rules.
Avoid maintaining two contradictory policies. If you keep Expires for compatibility or platform reasons, make sure it agrees with the Cache-Control strategy.
Cache-Control and Vary
Cache-Control decides whether and how a response may be reused, but the Vary header can influence which request headers are part of the cache key. For example, Vary: Accept-Encoding tells a cache that compressed and uncompressed representations should not be mixed.
An overly broad Vary policy can fragment a shared cache and reduce hit rates. Caching should therefore be reviewed as a system: Cache-Control, validators, cache keys, Vary, CDN configuration, and invalidation all matter.
Common Cache-Control Mistakes
- Using no-cache when the real requirement is no-store.
- Adding no-store together with long freshness values and expecting the freshness values to matter.
- Using long immutable caching on URLs whose content changes in place.
- Setting s-maxage and forgetting that it affects shared caches rather than private browser caches.
- Using aggressive shared caching for personalized or authenticated content without carefully controlling cacheability and cache keys.
- Expecting Cache-Control alone to purge copies that are already stored in intermediate caches.
- Forgetting validators such as ETag or Last-Modified when a policy relies on frequent revalidation.
Verify the Header After Deployment
A generated header is only the intended policy. Your framework, reverse proxy, CDN, hosting platform, or application middleware may add, replace, or strip headers before the response reaches the user.
After deployment, copy the actual response headers into FreeProKit’s HTTP Headers Parser to inspect the final header set in a readable form.
For CDN-backed sites, also test the response more than once and inspect headers such as Age or provider-specific cache-status headers when available. The exact signals differ by platform, so do not rely on the builder alone to prove a cache is behaving as intended.
Privacy and Processing
FreeProKit’s tools directory confirms this is a Website Management Tools utility. Adjacent FreeProKit header generators are described as JavaScript browser tools that process user-supplied values locally unless a live website/domain check is explicitly required.
Because the direct Cache-Control page was temporarily rate-limited during research, this content does not claim a specific processing statement for the builder beyond what can be verified from FreeProKit’s category framework. The tool itself builds a header value rather than needing to fetch a website unless the live interface explicitly adds a separate check.
Limitations
- The exact FreeProKit controls, presets, warning rules, and output variants could not be verified because the direct page returned a temporary 429 response to the crawler.
- A syntactically valid Cache-Control header does not guarantee that every browser, proxy, CDN, or hosting platform will behave identically.
- CDN configuration can override or supplement origin Cache-Control values.
- Cache-Control does not by itself define the complete cache key; headers such as Vary and platform rules also matter.
- Changing a Cache-Control header does not automatically purge a response that is already fresh in every intermediate cache.
- Caching user-specific or sensitive content requires careful testing beyond a generic header example.
Practical Examples
Example 1: Content-hashed static asset
A build pipeline outputs app.8f3a9c.js and creates a new filename whenever the file changes. A long max-age with immutable can be appropriate because an updated asset receives a new URL instead of overwriting the old one.
|
Cache-Control: public, max-age=31536000, immutable |
Example 2: HTML that should stay current
The homepage URL stays the same but the content changes. A no-cache policy allows storage while requiring validation before reuse. Pair it with a validator so unchanged HTML can be confirmed efficiently.
|
Cache-Control: no-cache |
Example 3: Browser and CDN use different lifetimes
A public response may be fresh only briefly in a browser but can remain fresh longer at the CDN edge. Use max-age for the general freshness lifetime and s-maxage to override it in shared caches.
|
Cache-Control: public, max-age=300, s-maxage=3600 |
Example 4: Sensitive response
A response contains sensitive information that should not be retained by caches. Use no-store rather than assuming no-cache prevents storage.
|
Cache-Control: no-store |
FAQ’s
What does a Cache-Control header do?
Cache-Control sends caching instructions to browsers and shared caches such as CDNs and proxies. Response directives can control storage, freshness, revalidation, shared-cache behavior, stale reuse, and related cache decisions. The correct policy depends on the type of content and the cache architecture.
What is the difference between no-cache and no-store?
no-cache allows the response to be stored but requires validation with the origin before reuse. no-store tells caches not to store the response. Use no-cache when storage is acceptable but freshness must be checked; use no-store when retention itself is the problem.
What is the difference between max-age and s-maxage?
max-age sets a response freshness lifetime in seconds and can apply to private and shared caches. s-maxage applies only to shared caches and overrides max-age or Expires there. This lets a CDN keep a response fresh for a different period than a browser.
When should I use Cache-Control: immutable?
Use immutable for resources that will not change while their current URL is valid, especially content-hashed or versioned static assets. Pair it with an appropriate freshness lifetime. Avoid long immutable caching for files that may change without changing their URL.
Can I use no-cache for HTML pages?
Yes. no-cache is a common revalidation-oriented policy for HTML that can change at the same URL. It allows the browser to store a copy but requires validation before reuse. ETag or Last-Modified can make that validation more efficient.
What do stale-while-revalidate and stale-if-error do?
stale-while-revalidate allows supported caches to temporarily serve a stale response while refreshing it in the background. stale-if-error allows supported caches to use stale content for a defined period when an upstream error occurs. They are independent extensions defined in RFC 5861.
Does Cache-Control replace ETag or Last-Modified?
No. Cache-Control defines cacheability, freshness, and reuse rules, while ETag and Last-Modified are validators that can make revalidation efficient. A policy using no-cache or stale revalidation can benefit from validators so unchanged content can return 304 Not Modified.
Does changing Cache-Control immediately clear every old cached response?
No. A new response header only affects responses that receive it. A fresh copy already stored in a browser, CDN, or intermediary may remain usable until it expires or is explicitly purged according to that cache system. Cache invalidation must be planned separately.
