Cloudflare Workers Static Assets vs. KV vs. R2: Where to Store Files at the Edge

When building a site or API on Cloudflare Workers, one of the first architectural decisions is where to put your files. A developer might try stuffing HTML bundles into Workers KV, serving user-uploaded PDFs from static build assets, or hitting R2 directly on every request for a tiny JSON config flag. Each of Cloudflare’s three storage options—Workers Static Assets, Workers KV, and Cloudflare R2—is built for a different access pattern, and picking the wrong one creates slow writes, awkward deployments, or unexpected latency.

Editorial illustration comparing Cloudflare Workers Static Assets, KV, and R2

Editorial illustration: match build-time site files to Static Assets, read-heavy small metadata to KV, and large objects or uploads to R2.

Summary

  • Use Workers Static Assets for your site’s build output (HTML, CSS, JS, images, _redirects, _headers) that deploys atomically alongside your Worker code via Wrangler.
  • Use Workers KV for high-read, low-latency key-value data (feature flags, routing maps, cached API JSON) where eventual consistency on writes is acceptable.
  • Use Cloudflare R2 for large objects, user uploads, backups, and media libraries with zero egress fees—and pair hot R2 objects with Cloudflare Cache or KV as noted in Cloudflare’s Dynamic Workers static assets pattern.
  • Never use Workers KV as a transactional counter or distributed lock because updates propagate globally asynchronously.

1. Workers Static Assets: Best for build-time website files

If you are deploying a static blog, Astro/Next.js front end, or SPA with an API Worker, Workers Static Assets is the simplest and cleanest home for your site files.

  • How it works: Wrangler uploads your build directory (_site/ or dist/) together with your Worker script in a single atomic deployment.
  • Why it fits: You do not have to write manual KV.get() or R2.get() boilerplate just to serve styles.css or index.html, and built-in _redirects and _headers work out of the box (see our guide on choosing between _redirects and Bulk Redirects).
  • When it does not fit: User-generated uploads or files that change independently of a Git/Wrangler code deployment.

2. Workers KV: Best for global read-heavy metadata and caching

Per Cloudflare’s Workers KV documentation, KV stores data centrally and caches reads globally at Cloudflare’s edge, making it fast for workloads where a key is written occasionally and read thousands of times per second.

  • Where KV shines:
    • Redirect lookup tables or tenant-routing maps updated via API without redeploying your Worker
    • Feature flags and maintenance-mode toggles
    • Caching expensive upstream API JSON responses across edge locations (cache data with Workers KV)
  • Where KV fails:
    • Strong consistency: Writes can take up to 60 seconds (or longer depending on cache TTL) to reflect across all global edge locations. Do not store inventory counts, rate-limit counters, or session locks in KV.
    • Large media files: Storing hundreds of megabytes of videos or large backups belongs in R2, not KV.

3. Cloudflare R2: Best for uploads, media, and large objects

R2 is Cloudflare’s S3-compatible object storage with zero egress fees. Unlike Static Assets, R2 lets your application or users upload, overwrite, and delete files dynamically at runtime without triggering a Wrangler deploy.

  • Where R2 shines:
    • User-uploaded avatars, PDFs, invoices, and media assets
    • Database backups and build archives
    • Large datasets or downloadable software packages
  • Performance tip: As Cloudflare’s Dynamic Workers documentation notes, a common pattern for hot files stored in R2 is fronting them with Cloudflare’s Cache API (or KV for small metadata) so repeated requests do not hit the R2 bucket every time.

Decision checklist: Pick the right layer in 30 seconds

  1. Does the file come from your npm run build step? → Workers Static Assets.
  2. Is it a small key-value lookup (under a few MB) read constantly and updated occasionally without strict real-time consistency? → Workers KV.
  3. Is it a user upload, PDF, video, backup, or large file updated independently of code deploys? → Cloudflare R2 (paired with Cache API or CDN-Cache-Control headers).
  4. Do you need strong transactional consistency, counters, or SQL queries? → Use Cloudflare D1 or Durable Objects instead of KV or R2.

Also remember to keep TLS hardened across any custom domain serving Workers or R2 buckets by following safe Cloudflare HSTS setup and checking DNS propagation with dig during cutovers.

Common mistakes

  • Using Workers KV to store user upload files or large PDFs. You pay unnecessary write/list friction and hit KV value-size limits when R2 was built specifically for object storage.
  • Expecting a KV.put() write to be visible immediately on every edge PoP. Eventual consistency means a read in another region (or even the same PoP while cached) can briefly return the previous value.
  • Serving R2 assets through a Worker without caching headers. Setting proper Cache-Control and CDN-Cache-Control headers avoids repeated Worker invocations and bucket reads for public images.

Why this matters

Choosing the right Cloudflare storage primitive early prevents painful data migrations later. Keep build artifacts in Static Assets, fast global lookups in KV, and runtime blobs in R2—and your Workers stay lean, fast, and predictable.

My Take

Start with Workers Static Assets for everything your build produces, add R2 the moment you need runtime file uploads or large media, and use Workers KV specifically as a globally cached key-value lookup table (never as a primary transactional database).

Conclusion

Store build-time HTML/CSS/JS in Workers Static Assets, high-read configuration or cached API snippets in Workers KV, and runtime uploads or large media in Cloudflare R2 with proper HTTP caching headers.

Sources