- What is the difference between stale-while-revalidate and stale-if-error?
SWR serves stale content while revalidating a fresh copy in the background, hiding latency. stale-if-error serves stale content when the origin is unreachable, hiding failures. They complement each other: SWR smooths the common case (slow origin), and stale-if-error smooths the rare case (broken origin). Most production deployments should enable both.
- Does stale-while-revalidate work in browsers?
Partially. Chrome and Firefox implement it in certain contexts; Safari support is incomplete. CDN edges (Fastly, Cloudflare, Akamai) support it more consistently. A deployment that depends on SWR should test the actual cache fleet, not assume RFC compliance equals universal implementation.
- What is a safe stale-while-revalidate window?
Match it to the outage you can tolerate hiding. A blog post can have a window of hours. A product price that must be accurate within minutes should have a window of seconds. The window is the interval during which you accept stale content without user impact — that is a business decision, not a technical one.
- Can I use stale-while-revalidate with APIs?
Yes, and it is increasingly common. An API that returns the same data repeatedly (user profile, product listing, search results) benefits from SWR exactly as HTML pages do. The caveat is that API clients may have their own caching logic; SWR at the edge and SWR in the client cache are separate layers.
- What happens if the origin never responds?
Within the SWR window, the cache keeps serving stale content. Outside the window, the cache treats the entry as missing and blocks the next request on a synchronous revalidation. If the origin is down, that revalidation fails and the cache returns an error (unless stale-if-error extends the window). The bound is what prevents SWR from becoming "serve stale forever".