stale-while-revalidate is one of the most useful cache-control tools for speeding up websites without forcing every request back to origin. Used well, it improves perceived performance, reduces origin load, and smooths over revalidation delays at the browser, reverse proxy cache, or CDN edge. Used carelessly, it can keep the wrong page, the wrong user state, or the wrong API response alive longer than you intended. This guide explains how to use stale-while-revalidate safely: where it fits in HTTP cache freshness, how to choose fallback windows, what to avoid on personalized pages, and how to combine it with cache purge, validation headers, and CDN rules so you get the speed benefit without serving the wrong content.
Overview
The short version: stale-while-revalidate lets a cache serve an expired response for a limited period while it fetches a fresh version in the background. That means the user gets a fast response now, and the cache updates itself immediately after.
Conceptually, a response moves through three states:
- Fresh: the cache can serve it normally.
- Stale but allowed: the cache may serve the old copy briefly while revalidating.
- Too old: the cache must fetch a new response before serving.
A common header pattern looks like this:
Cache-Control: public, max-age=60, stale-while-revalidate=30In this example, the response is fresh for 60 seconds. For the next 30 seconds, a supporting cache may serve the stale copy while checking the origin for an update. After that extra window, the cache should stop serving the expired object without a successful revalidation or refill.
This is especially valuable for edge caching and CDN for websites because the delay of a background fetch is often smaller than the delay of making the visitor wait on origin. It can also help improve TTFB for frequently requested pages that change often enough to need short freshness but not so often that every request must be dynamic.
But the safety rule matters more than the speed rule: only use stale-while-revalidate where a briefly stale response is acceptable. If the page is personalized, transaction-sensitive, inventory-sensitive, auth-dependent, or legally sensitive, you need much stricter controls or a full cache bypass. If you are still sorting out where your CDN should cache and where it should not, it helps to pair this topic with CDN Cache Bypass Rules Explained: Cookies, Query Strings, and Headers.
Core framework
To use stale-while-revalidate without serving the wrong content, work through the decision in five layers: cacheability, variation, freshness, revalidation, and invalidation.
1. Confirm the response is truly cacheable
Before tuning freshness, decide whether the response should be cached at all. Good candidates include:
- Public marketing pages
- Documentation pages
- Category pages with moderate update frequency
- Public API responses that tolerate brief lag
- Static or mostly static HTML generated from a CMS
Poor candidates include:
- Logged-in dashboards
- Cart and checkout pages
- Account pages
- Search results tied to user state
- Pages whose content changes per cookie, header, or session
If a response can show the wrong user, stale-while-revalidate is not your main problem. The page should not be shared-cacheable in the first place.
2. Define the cache key and variation clearly
Many stale content incidents are really cache key problems. A CDN or reverse proxy cache can only serve the right object if the cache key includes the dimensions that change the response. If the page varies by language, device class, country, or selected query parameters, those factors need to be reflected in your caching rules or normalized before caching.
Typical trouble spots include:
- Query strings that create unnecessary cache fragmentation
- Cookies that accidentally force bypass or accidentally get ignored
- Headers like
Accept-Languageor authorization state changing output - A/B test buckets leaking into shared cache
If your key is wrong, stale-while-revalidate simply preserves the wrong response more efficiently. For a deeper treatment of those variations, see CDN Cache Bypass Rules Explained.
3. Choose conservative freshness windows
The safest approach is to set max-age according to how fresh the content must be, then set stale-while-revalidate according to how much delay you are willing to hide from the user.
A useful mental model:
- max-age answers: “How long is this content definitely fresh?”
- stale-while-revalidate answers: “How long may I briefly serve the last known copy while I refresh it?”
That second window should usually be shorter than teams first assume. If your content updates every few minutes, giving it a very long stale window may undermine the point of short freshness. Start smaller, observe behavior, and expand only if the tradeoff is acceptable.
As a practical rule, make the stale window proportional to update risk:
- Low-risk static HTML: a modest stale window is often fine.
- Editorial pages with occasional updates: keep stale windows shorter and rely on purge when publishing changes.
- Commerce or pricing pages: be careful; often use very short stale windows or bypass key sections.
- Personalized pages: usually do not use shared stale-while-revalidate at all.
4. Pair it with validators, not just TTLs
stale-while-revalidate works best when the cache can revalidate cheaply. That usually means providing validators like ETag or Last-Modified. Then the cache can ask the origin whether the object changed, instead of always downloading a full replacement.
That matters for two reasons:
- It lowers origin bandwidth and processing cost.
- It makes background refresh faster and more predictable.
Without validators, a cache may need to refetch the entire object each time it revalidates. That still can work, but it is less efficient and can produce more origin load than expected.
5. Decide how changes will be pushed out
HTTP cache freshness is only one half of the story. The other half is invalidation. If the content can change suddenly and must be visible quickly, you need a purge strategy that matches your platform.
For many teams, the most reliable pattern is:
- Use moderate
max-age - Use a short stale-while-revalidate window
- Purge or tag-invalidate on publish or deploy
That gives you strong default performance without waiting on TTL expiry when important content changes. If you need a purge playbook, read How to Purge CDN Cache Without Breaking Your Site.
A safe decision checklist
Before enabling stale-while-revalidate, ask:
- Can this response ever contain user-specific content?
- What inputs change the output?
- How wrong would it be if a visitor saw the previous version for another 15 to 60 seconds?
- Do I have validators for efficient revalidation?
- Can I purge this object or group of objects quickly?
- Will the browser cache, CDN, and origin all interpret freshness in a compatible way?
Practical examples
Here are practical ways to apply stale-while-revalidate across common caching layers.
Example 1: Public marketing page behind a CDN
Suppose your homepage is public, updates a few times per day, and is served through a CDN edge delivery network. You want low latency and a strong cache hit ratio, but you also want homepage edits to show up quickly after publishing.
A reasonable pattern is:
Cache-Control: public, max-age=120, stale-while-revalidate=30Then pair that with purge-on-publish. Fresh responses are served for two minutes. During the next thirty seconds, an expired copy can still be served while the edge fetches the new one. If the editor publishes a major update, you purge the homepage path or related cache tags rather than waiting for the TTL.
This is a good use case because a visitor seeing the page from thirty seconds ago is usually acceptable, especially if your purge workflow is disciplined.
Example 2: Static assets with versioned filenames
For CSS, JS, fonts, and images with content-hashed filenames, stale-while-revalidate is usually less important than simply using long-lived immutable caching. If the filename changes on deploy, the new file URL becomes a new cache object.
In many setups, the better pattern is long freshness rather than a short stale window. If you are working through that strategy, see How to Cache Static Assets for Faster Core Web Vitals.
The lesson: do not use stale-while-revalidate as a substitute for good asset versioning.
Example 3: Headless CMS or API content
Suppose an API endpoint returns public article metadata. It updates throughout the day, but a short delay is acceptable. Here stale-while-revalidate can reduce origin pressure significantly.
Cache-Control: public, max-age=30, stale-while-revalidate=15This works best if responses include ETag and if query parameters are normalized carefully. If your API output varies on too many dimensions, the cache key can fragment badly and erase the benefit.
Be stricter for APIs than for plain HTML. Consumers may chain requests, and a stale API response can produce confusing application behavior if clients assume near-real-time accuracy.
Example 4: WordPress content pages
On WordPress, stale-while-revalidate is often useful for public posts and pages, but only if WooCommerce, membership, and logged-in paths are excluded correctly. A common mistake is to apply broad website caching rules to all HTML and then discover that account pages or cart fragments are being cached at the edge.
For mixed WordPress sites:
- Cache public post and page HTML conservatively
- Bypass logged-in users and admin areas
- Bypass cart, checkout, and account flows
- Purge on post update, theme deploy, or menu change
Related reads include WooCommerce Caching Rules: What to Cache and What to Bypass and How to Set Up Nginx FastCGI Cache for WordPress.
Example 5: Reverse proxy cache in front of origin
At the reverse proxy layer, stale-while-revalidate can be particularly effective because it shields the application from bursts of simultaneous revalidation. Instead of many clients waiting on origin when an object turns stale, the proxy can continue serving the old object while one refresh happens in the background.
This is a strong fit for Nginx, Varnish-style patterns, or managed caching solutions that sit in front of origin. If you are deciding between layers, compare this with Reverse Proxy Cache vs CDN: What’s the Difference and When Do You Need Both?.
Common mistakes
The fastest way to misuse stale-while-revalidate is to treat it as a universal performance flag. It is not. These are the mistakes that cause most trouble.
Using it on personalized responses
If a page varies by login state, customer tier, cart contents, or sensitive cookie values, shared caches should usually bypass it. A stale response is still the wrong response if it belongs to another session or user state.
Setting a stale window longer than your operational tolerance
Teams often focus on speed and forget editorial or business expectations. If product details can change quickly, a long stale window means visitors may continue seeing old text or old availability after freshness ends. That can be acceptable in some contexts, but it should be intentional.
Ignoring cache variation
Wrong content usually comes from an incomplete cache key, not from stale-while-revalidate itself. If your CDN merges multiple query-string variants into one cache object without understanding the effect on output, stale revalidation just extends the confusion.
Relying on TTL alone
Short freshness does not replace purge. If editors need immediate updates, add cache purge or tag invalidation to your publishing workflow. Otherwise you are asking TTL settings to solve a release management problem.
Skipping observability
You should know whether responses are HIT, MISS, REVALIDATED, or BYPASS at the CDN or reverse proxy. Expose cache status headers in staging where possible, log origin requests during rollout, and compare what the browser sees with what the edge sees. This also helps you improve cache hit ratio over time. A useful next step is How to Improve Cache Hit Ratio on a CDN.
Assuming every layer behaves the same way
Browsers, CDNs, and reverse proxies can differ in support and interpretation. Some setups honor stale directives at one layer but not another. Test your specific path: browser to edge, edge to origin, and purge behavior after content changes. If you use a platform-specific rule engine, such as Cloudflare caching controls, verify that your header strategy and platform rules are aligned rather than competing with each other. The practical baseline is in Cloudflare Cache Rules Guide: Common Setups That Actually Work.
When to revisit
stale-while-revalidate is not a set-and-forget directive. Revisit it when the content, the cache layer, or the business risk changes.
Update your approach when:
- You launch personalization, login, or segmentation on previously static pages
- You move from origin-only caching to a CDN or reverse proxy cache
- You add publish-time purge or cache tagging
- Your pages become more dynamic because of experiments, feature flags, or geolocation
- You change CMS, storefront logic, or API response shapes
- You see unexplained stale pages, low cache hit ratio, or inconsistent TTFB across regions
- New cache controls or platform features become available
A practical review routine is simple:
- Pick your top ten cached HTML routes and top API routes.
- Document whether each one is public, varied, or personalized.
- Write down current
Cache-Control, validator support, and purge method. - Reduce stale windows on anything with business-sensitive updates.
- Expand stale windows only where stale responses are clearly low risk.
- Test changes in staging, then verify edge headers and origin load in production.
If you are comparing CDNs or managed caching solutions, this review also helps you evaluate feature fit more clearly than a generic best CDN checklist. What matters is not whether a provider mentions stale caching, but whether you can control cache keys, bypass rules, validators, purge workflows, and observability cleanly in your environment.
The practical takeaway is straightforward: use stale-while-revalidate to hide latency, not to hide uncertainty. Keep it on public content, keep the fallback window deliberate, pair it with validators and purge, and treat cache variation as part of correctness. That is how you get the speed advantages of edge caching and website caching without letting stale content drift into wrong content.