Skip to content

Migrate from Pages to Workers

You can deploy full-stack applications, including front-end static assets and back-end APIs, as well as server-side rendered pages (SSR), with Cloudflare Workers.

Like Pages, requests for static assets on Workers are free, and Pages Functions invocations are charged at the same rate as Workers, so you can expect a similar cost structure.

Unlike Pages, Workers has a broader set of features available, including Durable Objects, Workflows, Containers, Cron Triggers, and comprehensive Observability. A complete list is in the compatibility matrix.

Migration

Migrating from Cloudflare Pages to Cloudflare Workers is often straightforward. The following are the most common steps to migrate your project.

Deployments and asset availability

Each Worker version has its own set of static assets. HTML and asset requests can use different versions while a deployment change spreads across the network, or during a gradual deployment. Older pages can also request files after a newer release starts serving traffic.

Review Version skew and static assets when migrating your release process. How long a file stays cached is separate from which versions can serve it. The Pages cache-retention description does not tell you how long Workers stores assets.

Frameworks

If your Pages project uses a popular framework, most frameworks already have adapters available for Cloudflare Workers. Switch out any Pages-specific adapters for the Workers equivalent and follow the framework guide.

For supported frameworks without an existing Workers configuration file, Wrangler can detect your framework, install the Workers adapter, and generate a wrangler.jsonc file with wrangler setup.

wrangler setup refuses to run while a Pages configuration file with pages_build_output_dir is present. If Wrangler does not detect a framework, a functions/ directory also identifies the project as Pages. For a supported framework, save the Pages configuration for rollback and move it out of the project before running setup. Otherwise, follow the framework guide or migrate the Pages Functions manually.

Project configuration

If your project does not already have one, create a Wrangler configuration file (either wrangler.jsonc, wrangler.json, or wrangler.toml) in the root of your project. The two mandatory fields are:

  • name

    Set this to the name of the Worker you want to deploy to. This can be the same as your existing Pages project name, as long as it conforms to Workers' name restrictions (for example, max length).

  • compatibility_date

    If you were already using Pages Functions, set this to the same date configured there. Otherwise, set it to the current date.

Build output directory

Where you previously configured a build output directory for Pages (in either a Wrangler configuration file or in the Cloudflare dashboard), set the assets.directory value for a Worker project.

Before, with Cloudflare Pages:

{
	"name": "my-pages-project",
	"pages_build_output_dir": "./dist/client/"
}
name = "my-pages-project"
pages_build_output_dir = "./dist/client/"

Now, with Cloudflare Workers:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"assets": {
		"directory": "./dist/client/"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"

[assets]
directory = "./dist/client/"

Serving behavior

Pages would automatically attempt to determine the type of project you deployed. It would look for 404.html and index.html files as signals for whether the project was likely a Single Page Application (SPA) or if it should serve custom 404 pages.

In Workers, to prevent accidental misconfiguration, this behavior is explicit and must be set up manually.

For a Single Page Application (SPA):

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"assets": {
		"directory": "./dist/client/",
		"not_found_handling": "single-page-application"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"

[assets]
directory = "./dist/client/"
not_found_handling = "single-page-application"

For custom 404 pages:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"assets": {
		"directory": "./dist/client/",
		"not_found_handling": "404-page"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"

[assets]
directory = "./dist/client/"
not_found_handling = "404-page"
Ignoring assets

Pages would automatically exclude some files and folders from being uploaded as static assets such as node_modules, .DS_Store, and .git. If you wish to also avoid uploading these files to Workers, you can create an .assetsignore file in your project's static asset directory.

dist/client/.assetsignoretxt
**/node_modules
**/.DS_Store
**/.git

Pages Functions

Full-stack framework

If you use a full-stack framework powered by Pages Functions, ensure you have updated your framework to target Workers instead of Pages.

Framework Pages setup Workers equivalent
Astro @astrojs/cloudflare targeting Pages @astrojs/cloudflare targeting Workers with wrangler.jsonc
SvelteKit @sveltejs/adapter-cloudflare targeting Pages @sveltejs/adapter-cloudflare with wrangler.jsonc
Nuxt Nitro cloudflare_pages preset Nitro cloudflare_module preset with wrangler.jsonc
Remix v2 @remix-run/cloudflare-pages Upgrade to React Router v7 with @cloudflare/vite-plugin.
Next.js @cloudflare/next-on-pages vinext or OpenNext
Hono hono/cloudflare-pages adapter Standard hono Worker entrypoint with @cloudflare/vite-plugin
SolidStart Nitro cloudflare_pages preset Nitro Workers output with wrangler.jsonc
Pages Functions with an "advanced mode" _worker.js file

If you use Pages Functions with an "advanced mode" _worker.js file, ensure this script does not get uploaded as a static asset. Either move _worker.js out of the static asset directory (recommended), or create an .assetsignore file in the static asset directory and include _worker.js within it.

dist/client/.assetsignoretxt
_worker.js

Then, update your configuration file's main field to point to the location of this Worker script. If your script calls env.ASSETS.fetch(), configure the ASSETS binding as shown below:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"main": "./dist/client/_worker.js",
	"upload_source_maps": true,
	"assets": {
		"directory": "./dist/client/",
		"binding": "ASSETS"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
main = "./dist/client/_worker.js"
upload_source_maps = true

[assets]
directory = "./dist/client/"
binding = "ASSETS"
Pages Functions with a functions/ folder

If you use Pages Functions with a folder of functions/, you must first compile these functions into a single Worker script with the wrangler pages functions build command.

npx wrangler pages functions build --outdir=./dist/worker/

The standalone Pages build command does not read compatibility settings from your Workers configuration. Pass the original Pages project's compatibility date with --compatibility-date and any compatibility flags with --compatibility-flags.

Although this command will remain available to you to run at any time, we do recommend considering using another framework if you wish to continue to use file-based routing. HonoX ↗︎ is one popular option.

Set main to the compiled Worker script and configure the ASSETS binding. The compiled script uses env.ASSETS.fetch() when no Function handles a request or middleware passes the request through without a response:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"main": "./dist/worker/index.js",
	"upload_source_maps": true,
	"assets": {
		"directory": "./dist/client/",
		"binding": "ASSETS"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
main = "./dist/worker/index.js"
upload_source_maps = true

[assets]
directory = "./dist/client/"
binding = "ASSETS"
_routes.json and Pages Functions middleware

If you authored a _routes.json file in your Pages project, or used middleware in Pages Functions, review how your Worker script routes requests. Pages defaults to running Pages Functions ahead of static assets, and _routes.json and middleware customize that behavior.

By default, Workers serves a matching static asset before invoking your Worker script. Set assets.run_worker_first to true to run your script before static assets on every request.

If you pass an array of route patterns (such as ["/api", "/api/*", "!/api/docs", "!/api/docs/*"]), positive matches run your Worker script first and negative (!) matches go directly to static assets. Paths that match neither keep the default behavior: a request can still invoke your Worker script if no asset matches and not_found_handling does not serve a fallback. In Pages _routes.json, /api/* also matches /api, but in run_worker_first it does not. List the bare path separately for any include or exclude that needs to match it.

Unlike _routes.json, an array does not limit Worker invocations to the listed paths. To preserve where your Pages Functions and middleware run, apply the original include and exclude rules in your Worker before dispatching to the compiled Functions. For requests outside that scope, return env.ASSETS.fetch(request) without dispatching to the Functions.

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"main": "./dist/worker/index.js",
	"upload_source_maps": true,
	"assets": {
		"directory": "./dist/client/",
		"binding": "ASSETS",
		"run_worker_first": ["/api", "/api/*", "!/api/docs", "!/api/docs/*"]
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
main = "./dist/worker/index.js"
upload_source_maps = true

[assets]
directory = "./dist/client/"
binding = "ASSETS"
run_worker_first = [ "/api", "/api/*", "!/api/docs", "!/api/docs/*" ]

After migrating your routing rules, remove _routes.json from your static asset directory or add /_routes.json to .assetsignore. Workers does not exclude this file from static asset uploads by default.

Starting from scratch

You can also start a new Worker script from scratch and use Wrangler's latest runtime features, such as WorkerEntrypoint, TypeScript support, and bundling:

./worker/index.jsjs
import { WorkerEntrypoint } from "cloudflare:workers";

export default class extends WorkerEntrypoint {
	async fetch(request) {
		return new Response("Hello, world!");
	}
}
./worker/index.tsts
import { WorkerEntrypoint } from "cloudflare:workers";

export default class extends WorkerEntrypoint {
	async fetch(request: Request) {
		return new Response("Hello, world!");
	}
}
{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"main": "./worker/index.ts",
	"upload_source_maps": true,
	"assets": {
		"directory": "./dist/client/"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
main = "./worker/index.ts"
upload_source_maps = true

[assets]
directory = "./dist/client/"
Translate Pages Functions, middleware, and Pages Plugins

When rewriting functions/ handlers into a native Worker instead of compiling them with wrangler pages functions build, map the Pages EventContext API to the standard Workers fetch(request, env, ctx) handler:

Pages Functions (EventContext) Cloudflare Workers (fetch(request, env, ctx))
context.request request
context.env env (configure assets.binding for env.ASSETS.fetch(request))
context.waitUntil(promise) ctx.waitUntil(promise)
context.passThroughOnException() To preserve an intentional static asset fallback, catch the error and return env.ASSETS.fetch(request). ctx.passThroughOnException() falls back to an origin server on a Worker Route, not to Worker assets.
context.next() env.ASSETS.fetch(request) (or await next() in Hono middleware)
context.params and context.data Framework router (such as Hono c.req.param() and c.set() / c.get()) or URLPattern

For example, a Pages _middleware.ts file that wraps static assets with a custom response header:

functions/_middleware.jsjs
export const onRequest = async (context) => {
	const response = await context.next();
	const updated = new Response(response.body, response);
	updated.headers.set("X-Frame-Options", "DENY");
	return updated;
};
functions/_middleware.tsts
export const onRequest: PagesFunction = async (context) => {
	const response = await context.next();
	const updated = new Response(response.body, response);
	updated.headers.set("X-Frame-Options", "DENY");
	return updated;
};

Becomes a Workers fetch handler (with assets.binding set to "ASSETS" and assets.run_worker_first configured for the paths you want to intercept):

src/index.jsjs
export default {
	async fetch(request, env) {
		const response = await env.ASSETS.fetch(request);
		const updated = new Response(response.body, response);
		updated.headers.set("X-Frame-Options", "DENY");
		return updated;
	},
};
src/index.tsts
interface Env {
	ASSETS: Fetcher;
}

export default {
	async fetch(request: Request, env: Env): Promise<Response> {
		const response = await env.ASSETS.fetch(request);
		const updated = new Response(response.body, response);
		updated.headers.set("X-Frame-Options", "DENY");
		return updated;
	},
} satisfies ExportedHandler<Env>;

If your project uses Pages Plugins (@cloudflare/pages-plugin-*), wrangler pages functions build compiles them into the generated Worker as a transition step. When moving to a native Worker, replace plugins with standard Workers integrations, such as calling the Turnstile siteverify API, validating Cloudflare Access JWTs, or using framework middleware.

Assets binding

Pages automatically provided an ASSETS binding to access static assets from Pages Functions. In Workers, the name of this binding is customizable and it must be manually configured:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"main": "./worker/index.ts",
	"upload_source_maps": true,
	"assets": {
		"directory": "./dist/client/",
		"binding": "ASSETS"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
main = "./worker/index.ts"
upload_source_maps = true

[assets]
directory = "./dist/client/"
binding = "ASSETS"

Runtime

If you had customized placement, or set a compatibility date or any compatibility flags in your Pages project, you can define the same in your Wrangler configuration file:

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"compatibility_flags": ["nodejs_compat"],
	"main": "./worker/index.ts",
	"upload_source_maps": true,
	"placement": {
		"mode": "smart"
	},
	"assets": {
		"directory": "./dist/client/",
		"binding": "ASSETS"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
compatibility_flags = [ "nodejs_compat" ]
main = "./worker/index.ts"
upload_source_maps = true

[placement]
mode = "smart"

[assets]
directory = "./dist/client/"
binding = "ASSETS"

Variables, secrets and bindings

Variables and bindings can be set in your Wrangler configuration file and are made available in your Worker's environment (env). Secrets can be uploaded with Wrangler or defined in the Cloudflare dashboard for production and .dev.vars for local development.

If you are using Workers Builds, ensure you also configure any variables relevant to the build environment there. Unlike Pages, Workers does not share the same set of runtime and build-time variables.

Wrangler commands

Where previously you used wrangler pages dev and wrangler pages deploy, now instead use wrangler dev and wrangler deploy. Additionally, if you are using a Vite-powered framework, the Cloudflare Vite plugin may be able to offer you an even simpler development experience.

Builds

If you are using Pages' built-in CI/CD system, you can swap this for Workers Builds by first connecting your repository to Workers Builds and then disabling automatic deployments on your Pages project.

Build environment variables

If your build scripts read default Cloudflare Pages build environment variables, update them to the Workers Builds default variables:

Pages build variable Workers Builds equivalent Notes
CF_PAGES WORKERS_CI Set to 1 during CI builds.
CF_PAGES_BRANCH WORKERS_CI_BRANCH Branch name from the push event.
CF_PAGES_COMMIT_SHA WORKERS_CI_COMMIT_SHA Full SHA-1 hash of the commit being built.
CF_PAGES_URL None Workers Builds does not inject a deployment URL at build time. Use a custom environment variable for canonical site URLs, or use WORKERS_CI_BUILD_UUID to identify a build.

CI/CD feature mapping

Preview environment

Pages automatically creates a preview environment for each project, and can be independently configured.

To get a similar experience in Workers:

  1. Add a previews block and enable workers.dev Preview URLs in your Wrangler configuration file.

    {
        "name": "my-worker",
        // Set this to today's date
        "compatibility_date": "2026-12-01",
        "main": "./worker/index.ts",
        "upload_source_maps": true,
        "assets": {
            "directory": "./dist/client/"
        },
        "preview_urls": true,
        "previews": {}
    }
    name = "my-worker"
    # Set this to today's date
    compatibility_date = "2026-12-01"
    main = "./worker/index.ts"
    upload_source_maps = true
    preview_urls = true
    previews = { }
    
    [assets]
    directory = "./dist/client/"
  2. Enable preview builds in Workers Builds.

  3. If an existing Workers Builds project still uses the previous preview model, complete the one-time switch to Worker Previews.

Optionally, you can also protect these Preview URLs with Cloudflare Access.

Headers and redirects

_headers and _redirects files are supported natively in Workers with static assets. Ensure that, just like for Pages, these files are included in the static asset directory of your project.

Caching and Cache Rules

Static assets on Workers are cached automatically across Cloudflare's network. By default, matching assets are served without invoking your Worker script.

On Pages, zone-level Cache Rules on a custom domain can cache responses from Pages Functions or an advanced mode _worker.js. On Workers, your Worker runs before the zone cache, so Cache Rules do not cache the responses it generates. To cache eligible Worker-generated responses, enable Workers Cache with "cache": { "enabled": true } in Wrangler and set appropriate Cache-Control headers on the responses you want to cache.

Cache Rules still apply to subrequests made with fetch(). Whether your Worker's cache settings override those rules depends on its compatibility flags. Refer to How Workers interact with Cache Rules.

pages.dev

Where previously you were offered a pages.dev subdomain for your Pages project, you can now configure a personalized workers.dev subdomain for all of your Worker projects. You can configure this subdomain in the Cloudflare dashboard, and opt-in to using it with the workers_dev option in your configuration file.

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-12-01",
	"main": "./worker/index.ts",
	"upload_source_maps": true,
	"workers_dev": true
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-12-01"
main = "./worker/index.ts"
upload_source_maps = true
workers_dev = true

Custom domains

If your domain's nameservers are managed by Cloudflare, you can, like Pages, configure a custom domain for your Worker. Additionally, you can configure a route if you only want a subset of paths to be served by your Worker.

Migrate a live custom domain

The dashboard cannot add a Workers Custom Domain on a hostname that already has a CNAME record, including a Pages custom domain. Wrangler can replace an existing record during Custom Domain setup. Review the DNS change before proceeding, regardless of which tool you use.

To move a live custom domain from Pages to Workers with minimal disruption:

  1. Deploy your Worker and verify it on its *.workers.dev subdomain or a Preview URL. Record the existing DNS record and Pages custom domain settings so you can restore them if needed.
  2. (Optional) To test production traffic before changing DNS records, add a temporary Worker Route matching your custom domain (for example, example.com/*) while the Pages custom domain is still active. Verify traffic reaches your Worker. At this stage, you can remove the route to return traffic to Pages.
  3. For a dashboard cutover, delete the Pages CNAME in DNS > Records, then remove the custom domain from Pages. Plan for a possible interruption between deleting the record and adding the Worker Custom Domain.
  4. Immediately add the Custom Domain to your Worker, remove the temporary Route if you created one, and verify traffic on the hostname again.

Keep the Pages project until you have verified the cutover. To roll back after the move, remove the Worker Custom Domain and restore the Pages custom domain and DNS configuration you recorded.

Rollout

Once you have validated the behavior of your Worker, are satisfied with the development workflows, and have migrated all of your production traffic, you can delete your Pages project in the Cloudflare dashboard or with Wrangler:

npx wrangler pages project delete

Migrate your project using an AI coding assistant

You can add the following migration prompt in your coding assistant (for example, Claude Code or Cursor) to help migrate your project to Workers:

https://developers.cloudflare.com/workers/prompts/pages-to-workers.txt

You can also connect the Cloudflare documentation MCP server (https://docs.mcp.cloudflare.com/mcp) in your coding assistant so your agent has up-to-date context when migrating from Pages to Workers.

Compatibility matrix

This compatibility matrix compares the features of Workers and Pages. Unless otherwise stated, what works in Pages works in Workers, and what works in Workers works in Pages. Think something is missing from this list? Open a pull request ↗︎ or create a GitHub issue ↗︎.

Legend
✅: Supported
🟡: Unsupported, workaround available
❌: Unsupported

Workers Pages
Writing, Testing, and Deploying Code
Cloudflare Vite plugin ✅ ❌
Rollbacks ✅ ✅
Gradual Deployments ✅ ❌
Preview URLs ✅ ✅
Testing tools ✅ ✅
Local Development ✅ ✅
Remote Development (--remote) ✅ ❌
Quick Editor in Dashboard ↗︎ ✅ ❌
Static Assets
Early Hints 🟡 1 ✅
Custom HTTP headers for static assets ✅ ✅
Middleware ✅ 2 ✅
Redirects ✅ ✅
Smart Placement ✅ ✅
Serve assets on a path ✅ ❌
Observability
Workers Logs ✅ ❌
Logpush ✅ ❌
Tail Workers ✅ ❌
Real-time logs ✅ ✅
Source Maps ✅ ✅ 3
Runtime APIs & Compute Models
Node.js Compatibility Mode ✅ ✅
Durable Objects ✅ 🟡 4
Workflows ✅ 🟡 5
Containers ✅ ❌
Cron Triggers ✅ ❌
Bindings
AI ✅ ✅
Analytics Engine ✅ ✅
Assets ✅ ✅
Browser Run ✅ ✅
D1 ✅ ✅
Email Workers ✅ ❌
Environment Variables ✅ ✅
Hyperdrive ✅ ✅
Image Resizing ✅ ❌
KV ✅ ✅
mTLS ✅ ✅
Queue Producers ✅ ✅
Queue Consumers ✅ ❌
R2 ✅ ✅
Rate Limiting ✅ ❌
Secrets ✅ ✅
Secrets Store ✅ ❌
Service bindings ✅ ✅
Vectorize ✅ ✅
Builds (CI/CD)
Monorepos ✅ ✅
Build Watch Paths ✅ ✅
Build Caching ✅ ✅
Deploy Hooks ✅ ✅
Branch Deploy Controls 🟡 6 ✅
Custom Branch Aliases ✅ 7 ✅
Pages Functions
File-based Routing 🟡 8 ✅
Pages Plugins 🟡 9 ✅
Domain Configuration
Custom domains ✅ ✅
Custom subdomains ✅ ✅
Custom domains outside Cloudflare zones ❌ ✅
Non-root routes ✅ ❌

Footnotes

  1. Workers can use Early Hints when the zone setting is turned on. Your Worker must send the appropriate Link headers. For more information, refer to the 103 Early Hints example. ↩

  2. The run_worker_first option controls whether your Worker script runs before static assets. With an array of patterns, a request that matches none of the patterns can still invoke the script if no asset matches and not_found_handling does not serve a fallback. Requests routed to the Worker script are billed as normal Worker invocations. ↩

  3. Pages Functions source maps require explicit opt-in (upload_source_maps: true or --upload-source-maps) and only apply to real-time logs. Workers source maps upload by default starting in Wrangler 4.150.0. On earlier versions, set upload_source_maps: true to opt in. Workers also supports source maps for Tail Workers and Workers Issues. ↩

  4. To use Durable Objects with your Cloudflare Pages project, you must create a separate Worker with a Durable Object and then declare a binding to it in both your Production and Preview environments. Using Durable Objects with Workers is simpler and recommended. ↩

  5. To call Workflows from Pages, you must deploy your Workflow in a separate Worker and invoke it via a Service Binding or fetch(). Defining Workflows directly inside a Static Assets Worker is simpler and recommended. ↩

  6. Workers Builds supports enabling preview builds, though it does not have the same level of configurability as Pages. ↩

  7. Use custom domain Preview URLs to serve branch Previews on your own domain. Unlike Pages, where you can point any hostname at a branch, Workers serves each Preview at <preview-name>.<your-domain>, and the Preview name defaults to the branch name. Cloudflare creates a wildcard DNS record and certificate for the domain you choose. ↩

  8. Workers supports popular frameworks, many of which implement file-based routing. Additionally, you can use Wrangler to compile your folder of functions/ into a Worker to help ease the migration from Pages to Workers. ↩

  9. As with file-based routing, Wrangler can compile your Pages Functions into a Worker. Or if you are starting from scratch, everything that is possible with Pages Functions can also be achieved by adding code to your Worker or by using framework-specific plugins for relevant third-party tools. ↩

Was this helpful?