Menu
Cloudflare Blog·July 6, 2026

Cloudflare Workers Cache: Edge Caching for Server-Rendered Applications

Cloudflare Workers Cache introduces a tiered cache directly in front of Workers, allowing server-rendered applications to leverage HTTP caching mechanisms like `Cache-Control` and `stale-while-revalidate` for improved performance and reduced CPU costs. This shifts the architecture where Workers act as the origin, providing a static-like experience without complex build-time prerendering or per-request rendering overhead. The cache is Worker-scoped, offering programmatic control and supporting content negotiation via `Vary` headers.

Read original on Cloudflare Blog

Cloudflare Workers Cache fundamentally alters the caching paradigm for applications running on Cloudflare Workers, especially those acting as the origin for server-side rendering (SSR). Previously, Workers sat in front of the cache and origin, giving control over what *reached* the origin. With Workers Cache, the cache now sits *in front of the Worker*, allowing Cloudflare to serve cached responses directly without invoking the Worker, significantly reducing latency and CPU costs for cacheable content.

Architectural Shift for SSR on the Edge

The introduction of Workers Cache addresses a critical gap for server-rendered applications deployed on Cloudflare Workers. When Workers evolved from being a proxy to becoming the primary origin, the benefits of Cloudflare's existing edge cache for the Workers' output were limited. Every request would hit the Worker, incurring latency and CPU costs. The new architecture enables a true SSR experience with edge caching, providing a third option between static site generation (SSG) and pure server-side rendering.

  • Old Model: Worker ">" Cache ">" Origin (Worker controls what hits cache/origin)
  • New Model: Cache ">" Worker ">" Origin (Cache can serve directly, bypassing Worker)

Leveraging HTTP Caching with stale-while-revalidate

A key feature is the full support for standard HTTP `Cache-Control` headers, particularly `stale-while-revalidate`. This directive allows Cloudflare to immediately serve a stale cached response while asynchronously refreshing it in the background by invoking the Worker. This pattern ensures users almost always receive a cache-speed response, even for content that is being updated, bridging the gap between static content speed and dynamic content freshness.

javascript
export default {
  async fetch(request) {
    const html = await renderPage(request);
    return new Response(html, {
      headers: {
        "Content-Type": "text/html; charset=utf-8",
        "Cache-Control": "public, max-age=300, stale-while-revalidate=3600",
      },
    });
  },
};

Worker-Scoped Cache and Content Negotiation

Unlike Cloudflare's traditional zone-level cache, Workers Cache is scoped to the individual Worker. This means caching behavior is controlled entirely by the Worker's code and its `Cache-Control` headers, rather than separate zone configurations or Page Rules. This isolation prevents conflicts between different Workers or other zone content and allows for programmatic purges specific to the Worker.

💡

Advanced Content Negotiation

The `Vary` HTTP header is fully supported, enabling the cache to store and serve different representations of a single URL (e.g., HTML vs. JSON, WebP vs. JPEG, different languages) based on request headers like `Accept` or `Accept-Language`. This is crucial for building robust, performant APIs and multi-format content delivery on the edge.

Cloudflare WorkersEdge ComputingCachingServer-Side RenderingHTTP CachingCDNDistributed SystemsPerformance Optimization

Comments

Loading comments...