Performance & EdgeAcronym: SWR

Stale-While-Revalidate (SWR)

Direct Definition

Stale-While-Revalidate (SWR) is an HTTP cache control extension that instructs the edge to serve an existing cached (stale) response instantly to the client, while asynchronously initiating a background fetch to refresh the cache. Users experience zero latency wait time while always receiving fresh data.

Technical Architecture & Deep-Dive

Traditional Time-to-Live (TTL) cache expiration forces the unlucky user who requests an expired item to wait for the complete origin roundtrip. If the origin is slow or executing complex aggregation, that user experiences noticeable lag.

SWR decouples cache freshness from response latency. Using `max-age=60, stale-while-revalidate=300`, the edge serves the cached payload instantly if requested within 360 seconds, and if older than 60 seconds, quietly dispatches a non-blocking background subrequest to update edge storage.

Key Architectural Benefits

Guarantees instant sub-10ms response times even when cache items expire.
Hides slow upstream API processing or database queries from client users.
Prevents synchronous latency spikes during high-concurrency traffic.
REALCOMPOSER EDGE WORKSPACE

Implement Stale-While-Revalidate (SWR) at the Edge

Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.

START BUILDING FREE

Frequently Asked Questions

Q:How do I specify SWR in HTTP headers?

Include the `stale-while-revalidate` directive in your `Cache-Control` header, for example: `Cache-Control: public, max-age=60, stale-while-revalidate=300`.

Related Architecture Concepts

Ready-to-Use Edge Recipes