Worker Previews: Branch URLs, Isolation, and CI Builds
How Cloudflare Worker Previews create isolated branch environments, Preview URLs, Workers Builds integration, and Wrangler configuration.
This page summarizes Cloudflare’s Worker Previews documentation: isolated, production-like environments for each branch under the same Worker, with their own code, settings, URLs, and observability—without replacing production traffic.
Worker Previews: what they are and when to use them
Section titled “Worker Previews: what they are and when to use them”Worker Previews are the recommended way to test branch and pull request changes before production.
Previews give each branch an isolated, production-like environment under the same Worker. Each Preview is configured with its own variables, secrets, and bindings, served on its own URL, and has its own observability.
— Cloudflare, Previews
Running npx wrangler preview on a feature branch creates or updates a Preview for that branch. Production on main still uses npx wrangler deploy with top-level settings. You do not need a production deploy before creating your first Preview, per Get started.
Previews versus Version URLs and Wrangler environments
Section titled “Previews versus Version URLs and Wrangler environments”For pull request and branch testing, use Previews—not Version URLs.
| Workflow | Best for | Command |
|---|---|---|
| Previews | Full environments for branches and PRs under the same Worker | npx wrangler preview |
| Version URLs | One uploaded version using that version’s production resources | wrangler versions upload |
| Wrangler environments | Separately deployed Workers | wrangler deploy --env <name> |
Version URLs use production resources. A Version URL runs one uploaded Worker version with the production resources configured for that version. It does not create isolated branch resources. Do not use Version URLs for branch or pull request testing. Use Previews instead.
— Cloudflare, Compare workflows
If you today use wrangler versions upload --preview-alias for PR review, Cloudflare recommends switching to npx wrangler preview (or npx wrangler preview --name staging) so you get branch isolation, Preview-specific settings, and automatic isolation for Durable Objects and Containers. See Migrate from aliased Version URLs to Previews.
Preview URL types: stable branch link and immutable deployment link
Section titled “Preview URL types: stable branch link and immutable deployment link”Each Preview exposes two URL patterns on workers.dev, a custom domain, or both.
| Role | Purpose |
|---|---|
| Preview URL | Always serves the latest deployment on that branch; share with reviewers |
| Deployment URL | Points to one exact deploy; never changes |
On workers.dev, examples follow <preview-name>-<worker-name>.<subdomain>.workers.dev (Preview) and <deployment-id>-<worker-name>.<subdomain>.workers.dev (deployment), as described in Previews — URLs and Custom domains.
When a Worker is connected to GitHub or GitLab via Workers Builds, PR comments can list both a Commit Preview URL (per commit/version) and a Branch Preview URL (stable alias from the branch name). The branch alias stays the same across commits and always tracks the latest version of that branch. See per-branch preview deployments.
Long branch names and DNS limits
Section titled “Long branch names and DNS limits”If a branch plus Worker name fits within DNS label limits, the alias uses the branch name as-is. Names of 64 characters or more are truncated and get a 4-character hash derived from the full branch name, so the same branch always gets the same hash. This requires Wrangler 4.30.0 or later and needs no extra configuration. Details are in Workers per-branch preview URLs now support long branch names.
Enable Preview URLs: opt-in on workers.dev and custom domains
Section titled “Enable Preview URLs: opt-in on workers.dev and custom domains”Preview URLs are no longer on by default for security.
To prevent the accidental exposure of applications, we’ve updated how Worker preview URLs (
<PREVIEW>-<WORKER_NAME>.<SUBDOMAIN>.workers.dev) are handled. We made this change to ensure preview URLs are only active when intentionally configured, improving the default security posture of your Workers.— Cloudflare, Preview URLs now default to opt-in
Enable at least one hostname to get a Preview URL. For workers.dev, set preview_urls = true in the Wrangler file and deploy, or turn on Preview under Worker URL on the Domains tab. Wrangler 4.34.0+ defaults preview_urls to false when unset, so explicit choice is encouraged. See Enable workers.dev Preview URLs.
For custom domains, configure a route with previews_enabled: true (and often enabled: false for preview-only hostnames). Cloudflare can create wildcard DNS and certificates (for example *.app.example.com). Use a dedicated preview hostname when production already uses many subdomains. Full steps are in Custom domains.
Configure the previews block: settings that do not inherit production
Section titled “Configure the previews block: settings that do not inherit production”Previews do not inherit production settings. Define Preview variables, bindings, and runtime options in a previews block in the Wrangler configuration file (the block is required but may be empty).
Previews do not inherit production settings. Define them in the previews block of your configuration file.
— Cloudflare, Configuration
Define Previews Base on your team’s base branch (for example main); Git carries the file into feature branches. When you run npx wrangler preview, Wrangler uses the configuration on your current branch as the source of truth. Dashboard Previews Base settings must still be copied into the Wrangler file to keep deployments in sync. See Setting your Previews Base configuration.
Important placement rules from What goes in the previews block:
- Keep
assets,compatibility_date, andcompatibility_flagsat the top level. - Put Preview-specific
vars, storage bindings (KV, D1, R2, and similar),queues.producers,define, andtail_consumersinpreviews. - Do not add Queue consumers, Cron Triggers, or production routes to
previews—they do not target Previews. - Service bindings from a Preview call the bound Worker’s production deployment.
Durable Objects and Containers get a new namespace, storage, app, and instances per Preview automatically. KV, D1, R2, and other account-level resources stay shared unless you bind the Preview to a separate resource. See Resources and isolation.
If Preview deployment succeeds but Wrangler warns about missing bindings, the URL may be live while runtime config is incomplete—copy missing bindings into previews with test-safe resource IDs.
Workers Builds: automatic preview builds and pull request comments
Section titled “Workers Builds: automatic preview builds and pull request comments”Connect a git repository to Workers Builds so non-production branches run a Preview command after the build command. By default that command is npx wrangler preview, which creates or updates a Preview and returns a Preview URL.
Preview builds are builds for branches that are not your production branch.
— Cloudflare, Build branches
How to turn on Preview Builds in the dashboard
Section titled “How to turn on Preview Builds in the dashboard”- In Overview, open your Workers project.
- Go to Settings → Build → Branch control.
- Enable Enable Preview Builds.
- Confirm the Preview command is
npx wrangler preview(or a custom variant that still invokesnpx wrangler preview).
Details are in Configure preview builds. The Preview command is also documented in Builds configuration. Changing it to npx wrangler versions upload creates a Version URL instead of an isolated Preview.
For GitHub and GitLab, when a commit is part of a PR/MR, Cloudflare posts build status and, when the build runs wrangler preview, a Preview URL. Later pushes on the same branch update the same Preview URL; each deployment also gets an immutable Deployment URL. See GitHub integration and GitLab integration.
Successful builds also show a Preview button on the build details page to open the latest preview URL, matching the Pages experience. See Access Workers preview URLs from the Build details page.
Workers that connected to Builds before Worker Previews must complete a one-time switch to the new model; after switching you cannot revert to the previous preview model that used production settings. See Existing Workers connected to Builds.
Automatic PRs from Workers Builds should be reviewed by checking configuration, testing the preview link in the PR description, then merging when satisfied. See Automatic pull requests.
You can create preview triggers via the Builds API with deploy_command: "npx wrangler preview" and branch filters that exclude production. Example in Builds API reference.
wrangler preview command: local and CI usage
Section titled “wrangler preview command: local and CI usage”Worker Previews require Wrangler 4.135.0 or later in the project dependency (not only a global install). See Get started — Before you begin.
npx wrangler previewUse --name <PREVIEW_NAME> when the Preview name should not default to the current Git branch. --json returns machine-readable output including URLs—useful in GitHub Actions or other CI, as shown in Examples. Command reference: wrangler preview.
Delete a Preview with npx wrangler preview delete --name <preview-name>. When a preview limit is reached, Cloudflare removes the least recently deployed Preview; each Preview keeps up to 100 deployments (500 Previews per Worker on paid plans, 100 on free). See Previews — Limits.
Test, debug, and common mistakes
Section titled “Test, debug, and common mistakes”Previews support Workers Observability (logs, traces, metrics) configured separately in the previews block so Preview telemetry does not mix with production. See Test and debug. In the dashboard, switch between Production and each Preview from the environment control next to the Worker name.
Common mistakes
- Using Version URLs or
wrangler versions uploadfor PR testing while expecting isolated branch data. - Leaving production bindings in Previews and writing to live KV, D1, or R2.
- Assuming preview_urls is enabled when
workers.devwas disabled; re-enable via dashboard orpreview_urls = true. - Containers Workers that implement Durable Objects: preview URLs are not generated; production builds should use
wrangler deploy. See Containers FAQ. - Relying on wrangler tail for Previews—it does not support targeting Previews per Test and debug — Current limitations.
- Declaring a binding only at the top level when code reads it from
envin Preview (for example Durable Objects), causing runtime errors.
For a Pages-like experience when migrating static projects, add previews, set preview_urls = true, and enable preview builds in Workers Builds. See Migrate from Pages to Workers — Preview environment.
How to check this on your site
Section titled “How to check this on your site”- Confirm the project depends on Wrangler 4.135.0+ and the Wrangler file includes a
previewsblock (even if empty). - Run
npx wrangler preview --jsonon a feature branch and open the Preview URL from the output; confirm production URLs are unchanged. - If using Workers Builds, open a pull request, verify the Cloudflare comment includes a Preview URL, push another commit, and confirm the branch Preview URL still resolves to the latest deploy.
- In the Cloudflare dashboard, open the Worker’s Preview environment and check Observability after sending a test request to the Preview URL.
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.