Skip to content

Get started

You can create a Preview for a new or existing Worker. You do not need to deploy a Worker to production before creating its first Preview.

Before you begin

Worker Previews requires Wrangler 4.135.0 or later. Update the project dependency because project commands do not use a newer global installation.

npm i -D wrangler@latest

Step 1: Configure Preview settings

Add a previews block to your Wrangler configuration file. Top-level settings define production, and the previews block defines Preview settings. The previews block can be empty if your Preview does not need separate settings.

Use test resources for bindings that can affect production. Previews bound to the same D1 database_id share data and schema changes. To isolate a Preview, configure a separate database.

{
  // ...
  "vars": {
    "ENVIRONMENT": "production"
  },
  // ...
  "previews": {
    // ...
    "vars": {
      "ENVIRONMENT": "preview"
    }
    // ...
  }
}
[vars]
ENVIRONMENT = "production"

[previews.vars]
ENVIRONMENT = "preview"

To determine which settings belong at the top level or in previews, refer to What goes in the previews block.

Settings that you add or import in the dashboard must also be copied to your Wrangler configuration file.

Step 2: Deploy a Preview

Cron Triggers do not invoke a Preview's scheduled() handler. To test scheduled logic, use the Preview testing workaround.

Preview URLs are public by default. Configure Cloudflare Access before sharing a Preview that contains private content.

Run the same Preview command locally or in your existing CI workflow:

npx wrangler preview

The Preview name defaults to your current Git branch. To choose a name, add --name <PREVIEW_NAME>.

To post Preview URLs automatically to pull requests or merge requests, connect your Git repository and use Workers Builds. New Workers use Worker Previews by default. If an existing Worker already uses Workers Builds, complete the one-time setup.

A successful deployment returns a Preview URL that always points to the latest changes. It also returns a Unique Deployment URL for each deployment, so you can access earlier versions in the Preview's deployment history.

Next steps

Was this helpful?