14 Nov 2026 · 6 min read · EN
How Cache-Control: stale-while-revalidate works and how to use it safely on cPanel sites
stale-while-revalidate lets caches serve an expired response immediately while revalidation happens in the background. This guide shows what it means, how to set it (htaccess and LSCache), CDN caveats, and how to test it on cPanel sites.
By Tim Gocelerus
Problem
When a cached page expires, the first visitor often waits while the origin regenerates the response. Cache-Control: stale-while-revalidate avoids that wait by letting caches serve a stale copy immediately while they refresh the object in the background.
What stale-while-revalidate actually does
stale-while-revalidate is a Cache-Control response directive that tells caches they may immediately serve a stale response while revalidating (in the background) with the origin. It is intended to hide revalidation latency from clients by allowing background refreshes while returning the stale object to the requester.
Important rules you must follow
- stale-while-revalidate must be used together with a freshness lifetime such as max-age. The cached response is considered fresh for that max-age, and only after max-age has passed can the stale-while-revalidate window be used.
- The directive grants a short period where caches may return slightly stale content to avoid blocking clients while the fresh copy is fetched.
Sources: RFC 5861 and MDN explain the protocol-level meaning and constraints of this directive.
Where to set it on a cPanel site
You have two common approaches on cPanel hosting:
- Application/plugin-level (WordPress + LSCache): use the LiteSpeed Cache plugin settings.
- Webserver/.htaccess: emit Cache-Control headers from .htaccess when you control the file.
Both are valid; pick one so you don't emit conflicting headers.
LSCache for WordPress (if you use the LSCache plugin)
In the plugin UI the relevant screens are under:
- LiteSpeed Cache > Cache > TTL
- LiteSpeed Cache > Cache > Purge
Key settings and labels to look for:
- Default Public Cache TTL — set your normal max-age here.
- Serve Stale — this toggle (under the Purge tab) turns on serve-stale behaviour so visitors can receive a stale cached copy while LSCache regenerates in the background.
- Default Public Cache TTL Stale (sometimes shown as a "stale TTL" field) — lets you specify how long after expiry a stale copy may be served while revalidation runs.
Practical pattern: pick a normal TTL appropriate to the page type (home/category pages tend to be longer; frequently-changing pages shorter), and set the stale TTL larger than the normal TTL (for example, stale = 2× normal TTL) so a background refresh has breathing room. The plugin documentation and community guides recommend this pattern.
.htaccess (when you edit files via cPanel File Manager)
If you prefer to set headers in .htaccess, you can emit a Cache-Control header that includes stale-while-revalidate. Examples:
- Using a Header directive (common and explicit):
<IfModule mod_headers.c>
Header set Cache-Control "public, max-age=3600, stale-while-revalidate=1800"
</IfModule>
- If your server supports the LiteSpeed environment variable method, you can set an env var with a RewriteRule (useful when integrating with other rewrite rules):
RewriteEngine On
RewriteRule .* - [E=cache-control:public, max-age=3600, stale-while-revalidate=1800]
Notes:
- Replace the numeric values with the TTLs you chose.
- Do not omit max-age; stale-while-revalidate is only meaningful when a freshness lifetime is defined.
- If you run LSWS/OpenLiteSpeed and your host exposes server-level controls, there may also be server directives that limit how long stale content may be served (see next section).
Server-level limits and LSWS settings
LiteSpeed Web Server has server-level settings that can affect serve-stale behaviour. For example, LSWS introduced CacheMaxStaleAge to control maximum stale age the server will serve; that setting is a server/vhost config (httpd_config.conf or vhost config) rather than a .htaccess or plugin option. OpenLiteSpeed also exposes cache settings in WebAdmin.
If you do not manage the server configuration yourself (typical on shared cPanel hosting), ask your host whether a server-level max-stale setting exists and what value it enforces.
CDN caveats
CDNs vary in how they treat stale-while-revalidate and related headers:
- Some CDNs honor origin Cache-Control including stale-while-revalidate;
- Others ignore the directive, or provide their own equivalent (or control it with a separate setting in the CDN dashboard).
Before relying on origin headers, check your CDN's documentation or dashboard for any feature named like "serve stale", "stale-while-revalidate", "origin cache control", or revalidation options. If you are testing on a CDN-enabled site and results look inconsistent, re-run tests while bypassing the CDN (for example, request the origin directly if you have a way) or enable a CDN development mode that serves origin headers.
How to test it (quick checks you can run)
- Verify the header is being returned
- From a terminal, request headers for a page you configured:
curl -I https://example.com/some-page
- Look for a Cache-Control header that contains both max-age and stale-while-revalidate. Example to expect:
Cache-Control: public, max-age=3600, stale-while-revalidate=1800
If you do not see the header, check whether a plugin, .htaccess rule, or server config is overwriting it.
- Exercise the serve-stale behaviour (LSCache example)
- In WordPress: enable Serve Stale under LiteSpeed Cache > Cache > Purge and set your TTLs under LiteSpeed Cache > Cache > TTL.
- Purge the page you want to test (use the plugin purge or the URL-specific purge option).
- Immediately fetch the page from a client that will hit your site (or bypass the CDN). Observe whether the page is returned quickly even while the origin work to rebuild is happening.
To confirm caching behavior, inspect response headers (Cache-Control and Age) and compare response times. If using a CDN, repeat while bypassing the CDN to isolate origin behaviour.
- If results differ across requests
Remember that a background revalidation is invisible to the client: the first request after expiry can return a stale copy quickly, while the cache refreshes. Subsequent requests should receive the fresh copy.
Practical TTL suggestions and safety
- Assign TTLs by page type: rarely-changing marketing pages get longer max-age; dynamic pages get shorter.
- Set the stale TTL larger than the normal TTL (a common pattern is stale = 2× normal TTL) so the cache has time to revalidate without dropping back to a slow origin render.
- Do not publish stale-while-revalidate without also setting a sensible max-age.
- If your host enforces a server-level cache max-stale, coordinate TTLs with that limit.
Summary and next steps
stale-while-revalidate gives you a controlled way to trade a short period of slightly-stale content for faster responses on the first request after expiry. You can set it in .htaccess or in LSCache plugin settings (LiteSpeed Cache > Cache > TTL and the Purge tab’s Serve Stale and stale TTL fields). Check your CDN’s docs because CDNs may ignore or override origin directives. Test with curl -I to confirm the header and exercise the enable/purge/request cycle to observe behaviour.
If you host on Gocelerus, note that Gocelerus is cPanel web hosting for Southeast Asia, serving Indonesia and Cambodia first; servers are in Singapore, with NVMe storage, LiteSpeed web server and Imunify360 security; daily backups are included; and moving an existing website to Gocelerus is free (the team does the migration). Plans and prices are at https://gocelerus.com/pricing.
Sources
Manage your cPanel servers from one dashboard
Connect your WHM to Gocelerus and manage PHP, SSL, and WordPress across all your cPanel accounts from one place.