Skip to Content
Docs03. AI-Powered Development22. Low-Cost Hosting: R2 + CDN

Low-Cost Hosting with Cloudflare R2 and CDN

Game sites and image-heavy sites generate massive bandwidth. Traditional hosting bills scale with traffic, potentially exceeding ad revenue. Cloudflare R2 combined with CDN caching eliminates most of that cost.

The Bandwidth Problem

Scratch games packaged as single HTML files can be several megabytes each. Image galleries serve high-resolution files repeatedly. Every visitor download counts against bandwidth allocation.

Standard cloud storage charges for egress. As traffic grows, bandwidth bills grow proportionally. A viral hit can create costs that dwarf any advertising income.

How R2 Plus CDN Solves This

Cloudflare R2 is object storage without egress fees. You pay for storage space and request operations, but the actual bandwidth is free. This changes the economics completely.

The remaining cost is request operations. Each time someone fetches a file from R2, that counts as an operation. High traffic still generates high operation counts.

CDN caching eliminates most operations. Configure proper cache headers, and Cloudflare’s CDN stores your files at edge locations worldwide. Most visitors get served from cached copies. Actual R2 fetches drop to a fraction of total requests.

Implementation Architecture

Upload static files to an R2 bucket. Create a Cloudflare Worker that fetches from R2 and sets aggressive cache headers. The Worker adds Cache-Control: public, max-age=31536000 to tell CDN nodes and browsers to cache the file for a year.

Bind your R2 bucket to the Worker, deploy it, and attach a custom domain. Visitors request files from your domain. Cloudflare’s edge checks cache first. Only cache misses reach the Worker and R2.

For static files that rarely change, this architecture results in near-zero ongoing costs regardless of traffic volume. The first visitor to each edge location triggers an R2 operation. Every subsequent visitor at that location gets the cached copy.

When This Works Best

This approach fits static assets perfectly: game files, images, videos, downloadable PDFs. Any file that doesn’t change frequently and gets served identically to every visitor benefits from aggressive caching.

Dynamic content or personalized responses don’t benefit the same way. Cache keys would need to include user-specific parameters, fragmenting the cache and reducing hit rates. Keep dynamic needs separate from static asset serving.

For game landing pages, serve the HTML through your normal hosting while embedding game files from the R2-backed CDN domain. The HTML stays dynamic if needed. The heavy files get the cost-efficient treatment.

Last updated on