Astro Themes & Starters

Astro on Cloudflare: Pages vs Workers, the Adapter, Bindings, and the Gotchas

21 October 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

Run Astro on Cloudflare properly: when static output is enough, when you need the adapter and Workers, how bindings work, the free-tier limits, and the deployment gotchas that bite first-timers.

Checklist inside: Astro on Cloudflare Deployment Checklist

Contents
  1. The short version
  2. Route 1: static Astro, no adapter
  3. Pages or Workers for a static site?
  4. When you actually need the adapter
  5. What the free tiers actually allow
  6. Bindings: how your Worker reaches Cloudflare services
  7. Environment variables and secrets
  8. The gotchas that actually bite
  9. How we researched this
  10. The deployment checklist
  11. What to do next

Pick the wrong shape for an Astro site on Cloudflare and nothing breaks loudly — it just gets more complicated than it needed to be, one binding and one config file at a time. The decision that matters is not the Pages-versus-Workers label. It is whether any page on your site genuinely needs to be rendered per request.

This guide makes that decision properly. It covers the static route, the current adapter (which deploys to Workers, not Pages — a change older tutorials have not caught up with), how bindings and secrets work, and the free-tier limits in real numbers.

Everything below is drawn from Astro’s and Cloudflare’s official documentation, with plan limits checked in November 2026 against Cloudflare’s published limits and pricing pages.

The short version

Shape What runs Pick it when
Static on Pages Nothing — built HTML served from the CDN Blogs, docs, directories, marketing sites
Static on Workers Nothing — same files, deployed with Wrangler New projects that may grow server features later
Adapter on Workers A Worker renders opted-out routes per request Personalisation, per-request redirects, live database reads

The verdict: if every page can be built ahead of time, stay static. Add the adapter the day a named feature needs the request itself — not before.

Route 1: static Astro, no adapter

If your site builds to static HTML, deployment needs no adapter and no server runtime. On Cloudflare Pages, you connect the repository, set the build command to npm run build and the output directory to dist, and you are done — the step-by-step version is in deploying an Astro site on Cloudflare Pages.

Cloudflare’s own docs now steer new projects toward Workers instead, where a static site deploys with a small wrangler.jsonc file pointing at the same dist folder. Both routes serve the same files on the same terms: static asset requests are free and unmetered on every plan. Existing Pages projects do not need to move; pick Workers for a new project mainly if you expect to add server routes later, because that is where the adapter now lives.

Staying static is not a limitation to apologise for. Search, forms, and comments all have client-side or third-party patterns that keep the build static, as covered for forms in handling forms and email on static Astro sites.

Pages or Workers for a static site?

Since both routes serve identical files, the choice is about workflow, not output:

Pages Workers (static assets)
Deploy from Git Built in — connect the repo Workers Builds, or Wrangler from your own CI
Deploy from your machine wrangler pages deploy wrangler deploy
Configuration lives in Dashboard settings + build config wrangler.jsonc in the repo
Rollback One click in the dashboard Redeploy a previous version
Server features later Pages Functions (legacy path for Astro) The current adapter’s home

For a site you know will stay static, Pages is still the least-effort route and there is no penalty for choosing it. For a site that might grow an API route, a login, or a database, starting on Workers means the adapter later is a config change, not a migration. Either way, _redirects and _headers files in your output work on both, so your URL management survives the choice.

When you actually need the adapter

The @astrojs/cloudflare adapter is what lets routes render on demand. Install it with npx astro add cloudflare, which adds the adapter to your config and generates a wrangler.jsonc for you.

Legitimate reasons to reach for it:

With the current adapter, pages are prerendered by default. A route opts into per-request rendering with export const prerender = false in its frontmatter. That default is the right shape for content sites: articles stay fast static files while your one dynamic route gets its Worker. The mental model matches Astro islands — static by default, dynamic only where you deliberately pay for it.

Deploys then run through Wrangler (npx wrangler deploy) or Workers Builds, Cloudflare’s Git-connected build system — not the Pages pipeline. Workers Builds gives you the same push-to-deploy habit as Pages, including preview versions of the Worker for non-production branches, so moving routes on demand does not cost you the review workflow.

One setting deserves attention at setup time: the compatibility date in wrangler.jsonc. It pins the runtime behaviour your Worker was built against, so Cloudflare can evolve the platform without changing how your code runs. Set it to the day you configure the project, and only move it deliberately, after reading what changed — never as a reflex when something unrelated breaks.

Note: older tutorials describe the adapter deploying to Pages as a Pages Function. That was the previous design. The current adapter targets Workers, and Cloudflare’s Astro guide is written for Workers.

What the free tiers actually allow

“Free” on Cloudflare is generous but specific. These are the numbers that shape an Astro site, from Cloudflare’s official limits and pricing pages, checked November 2026:

Service Free allowance Where it bites
Pages builds 500 builds/month, 1 at a time, 20-minute timeout Very active repos sharing one account
Pages site size 20,000 files, 25 MiB per file Media-heavy sites — large files belong in R2
Static requests Unlimited, unmetered bandwidth Does not bite
Workers requests 100,000/day, 10 ms CPU per request Heavy per-request rendering
D1 database 5 million rows read/day, 100,000 rows written/day, 5 GB storage Write-heavy apps; queries fail past the daily cap
Workers KV 100,000 reads/day, 1,000 writes/day, 1 GB storage Counters and anything written per request

The Cloudflare Pages free tier entry and the Cloudflare D1 free tier entry track these allowances as they change. The pattern to notice: reading is cheap everywhere on Cloudflare, writing is where the free tiers end.

Bindings: how your Worker reaches Cloudflare services

Bindings connect a Worker to platform services — KV (key-value storage), D1 (SQL database), R2 (object storage), and plain variables — without API keys or network calls. You declare them in wrangler.jsonc:

{
  "name": "my-site",
  "compatibility_date": "2026-11-01",
  "compatibility_flags": ["nodejs_compat"],
  "d1_databases": [
    { "binding": "DB", "database_name": "app-db", "database_id": "..." }
  ],
  "kv_namespaces": [
    { "binding": "CACHE", "id": "..." }
  ]
}

In an on-demand route or endpoint, you read them from the cloudflare:workers module:

---
export const prerender = false;
import { env } from "cloudflare:workers";
const row = await env.DB.prepare("SELECT * FROM posts WHERE slug = ?").bind(Astro.params.slug).first();
---

Two disciplines matter. Declare bindings identically in your local config and your deployed environments, because a binding that exists in production but not in local development produces the classic inversion of “works on my machine”: it fails on your machine, in preview, the night before launch. And treat binding names as part of your codebase — renaming one in a dashboard without updating config is a production incident with extra steps.

The adapter also wires up two bindings of its own: a SESSION KV namespace that powers Astro’s session support, and an IMAGES binding for on-request image transforms. You did not write them, but they appear in your deploy output, and the session namespace is provisioned on first deploy.

Which storage service fits which job:

Need Use Why
Config, flags, cached lookups KV Read-heavy, tolerant of eventual consistency
Relational data, queries, joins D1 Real SQL, priced by rows read and written
Files, uploads, media over 25 MiB R2 Object storage with no per-request row maths
Per-visitor session state Astro sessions (KV) The adapter manages the binding for you

Reaching for D1 to store uploaded files, or KV to run relational queries, is the usual beginner mismatch. Match the shape of the data to the service and the free allowances in the table above go a long way.

Environment variables and secrets

Non-secret configuration can live as plain variables per environment — production and preview separately. Check both, because a preview deploy reading production values is a quiet disaster.

Real secrets belong in secret storage (npx wrangler secret put for Workers, or the dashboard’s encrypted variables), never in the repository. For local development, the adapter reads a .dev.vars file, which belongs in .gitignore from the first commit.

One Astro-specific trap: anything exposed to the browser is public by definition. Variables Astro inlines into client code — the ones with the public prefix — should be audited the way you would audit what a server can reach: by assuming the list will be read by strangers. If a value would embarrass you in view-source, it is not a public variable.

The gotchas that actually bite

How we researched this

This guide is desk research, not a benchmark. The adapter behaviour, binding mechanics, and deploy flow come from Astro’s official Cloudflare deploy guide and Cloudflare’s Astro framework guide. Every limit in the table comes from Cloudflare’s official Pages limits, Workers pricing, D1 pricing, and KV pricing pages, checked November 2026. Limits change; the linked directory entries track the current figures.

The deployment checklist

Frequently asked questions

Do I need the Cloudflare adapter for a blog? No. A blog is static content; Pages or Workers static hosting serves the built output directly. You need the adapter only for routes that render per request.

What is the difference between Cloudflare Pages and Workers for Astro? Pages is a hosting and deployment pipeline built around sites; Workers is the serverless runtime. A static Astro site can live on either. On-demand rendering now belongs to Workers: the current adapter deploys there, with prerendered pages served as static assets alongside it.

Can I use a database with Astro on Cloudflare? Yes — D1 is the native option, reached from on-demand routes through a binding. That requires the adapter and at least one route with prerender = false, which is why it belongs in the “genuine need” column. On the free plan D1 allows 5 million rows read and 100,000 rows written per day (checked November 2026).

Why does my site work locally but fail after deploying with the adapter? Most often a Node.js API the Workers runtime does not provide, or a binding or variable that exists locally but not in the deployment environment. Compare environments first; it is the cause more often than code is.

What to do next

Decide your mode honestly using the first checklist item, deploy the static version if that is all you need, and keep the adapter in your pocket for the first feature that truly requires it. When that feature arrives, the move is an afternoon of config, not a replatform — which is exactly why there is no prize for doing it early. If you are starting from zero, hosting a static site for free compares the realistic options, and choosing your theme before connecting the repo saves the common redeploy churn of swapping themes after launch. Once the site is live, the honest Astro SEO guide covers what to verify about the setup you just deployed.

Category: Astro Themes & Starters · Tags: #astro #cloudflare #deployment #hosting

Next step: this article is part of Astro guides, which covers the full topic from first setup to advanced use.

Related guides