Cloudflare Pages Deployment Guide
Git-connected static and SSR deploys on Cloudflare's global edge network with Workers and Functions.
Why
Cloudflare Pages serves static assets and SSR from 300+ edge locations with no cold starts and free unlimited bandwidth on the free plan. Workers integrate for edge logic (auth, A/B testing, geo-routing) with 0ms cold start, unlike serverless functions on other platforms.
Cloudflare's edge network spans 330+ cities with sub-50ms p95 latency globally. Edge functions reduce TTFB by 60-80% compared to origin servers, and Akamai reports 40% of enterprises now use edge compute in 2024.
When
Choose Cloudflare Pages for static sites, Astro/Next.js SSR, edge-heavy apps (geo-routing, auth at edge), and cost-sensitive projects needing free unlimited bandwidth. Avoid if you need long-running processes or heavy compute (use Fly.io or a VPS).
How
Example
Common Problems
- ⚠Build fails with 'wrangler not found' — Pages dashboard needs wrangler in devDependencies, not global
- ⚠Functions timeout at 30s — edge CPU limit, move long tasks to a Durable Object or external service
- ⚠D1 database not bound — wrangler.toml binding name doesn't match env.DB reference in code
- ⚠Custom domain shows 'pending' — DNS propagation takes up to 24h, or CNAME points to wrong target
Best Practices
- ✓Pin @cloudflare/workers-types and wrangler versions — edge runtime API changes between versions
- ✓Use _routes.json to limit Functions to /api/* — static assets served faster without function invocation
- ✓Set compatibility_date in wrangler.toml — opt into stable runtime features predictably
- ✓Use D1/KV/R2 bindings for state — edge functions are stateless, persistence needs a binding
FAQ
How is Cloudflare Pages different from Vercel?
Pages runs on Cloudflare's edge network (300+ cities) with no cold starts, while Vercel runs in a single region by default. Pages is free for unlimited static sites; Vercel charges per bandwidth beyond the free tier.
Can I use server-side rendering on Pages?
Yes, via Pages Functions (Workers) — add a functions/ folder with on-demand routes. They run on the edge with a 50ms CPU limit. For heavy SSR, use a Node.js framework on a different platform.
Why is my build failing with wrangler not found?
Pages uses its own build environment — install wrangler as a devDependency and set the build command to npx wrangler pages deploy. For framework presets (Next.js, Astro), select the preset in the dashboard instead.
How do I set up a custom domain on Pages?
Add the domain in the Pages dashboard, then add a CNAME record pointing to your-pages-project.pages.dev. Cloudflare-managed domains are automatic. DNS propagation takes under 60s on Cloudflare's network.
How do I deploy a monorepo to Pages?
Set the root directory in the Pages dashboard to your app folder. Pages builds only that directory. For Turborepo, use npx turbo run build --filter=<app> as the build command.