Integration Guides · 6 MIN

How to deploy a static site to Cloudflare Workers with Wrangler

Deploy a static site on Cloudflare Workers static assets with Wrangler, add a Worker only where you need code, and use .assetsignore so private files never go live.

By NactorePublished 22 Nov 2026All articles

To deploy a static site to Cloudflare Workers, point the assets.directory setting in wrangler.jsonc at your built files, test with wrangler dev, then run wrangler deploy with that config file named explicitly. If the assets directory is your repo root, add an .assetsignore file first, because Wrangler uploads everything else in it. This guide shows the setup we run and the tests that prove it.

Key takeaways
  • Workers static assets serves plain files directly, and your Worker code runs only for the routes you choose.
  • .assetsignore uses .gitignore syntax and lives in the root of the assets directory.
  • Without it, our local test served /.env, /.git/config and the Worker source with status 200.
  • _headers and _redirects files work on Workers static assets the same way they do on Pages.
  • Always name the config file and dry-run before a deploy, then check the output names the Worker you expected.
  • Nactore is a technology and growth company that builds, ships, ranks and grows products, and our own site is deployed this way.

How do you host a static site on Cloudflare Workers?

Cloudflare Workers hosts a static site through static assets. Wrangler uploads a folder of HTML, CSS and images, and Cloudflare serves any request that matches a file without running code. You add a Worker script only when a route needs logic, such as a contact form or an API. One project then covers both.

QuestionPagesWorkers static assets
Plain static filesYesYes
_headers and _redirectsYesYes, natively supported
Server code on some routesPages FunctionsThe Worker, with run_worker_first
Wider platform featuresFewerCloudflare calls the Workers feature set "distinctly broader"

Cloudflare's static assets docs cover the full option list.

Step 1: Write the Wrangler config

A small site needs four files plus your pages. This is the layout we tested.

my-site/
  index.html
  404.html
  blog/first-post.html
  _headers
  .assetsignore
  worker.js
  wrangler.jsonc
{
  "name": "my-site",
  "main": "worker.js",
  "compatibility_date": "2026-11-01",
  "assets": {
    "directory": ".",
    "binding": "ASSETS",
    "html_handling": "auto-trailing-slash",
    "not_found_handling": "404-page",
    "run_worker_first": ["/api/*"]
  }
}

Set compatibility_date to the day you create the project. not_found_handling: "404-page" serves your 404.html with a real 404 status. With html_handling set, /blog/first-post serves blog/first-post.html.

Step 2: Run code only where you need it

By default a request that matches a file never reaches your Worker. run_worker_first sends the listed paths to the Worker first, so /api/* gets code while every page stays a plain file.

// worker.js
export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    if (url.pathname === "/api/health") {
      return Response.json({ ok: true });
    }
    return env.ASSETS.fetch(request); // everything else is a static file
  },
};

Security headers go in _headers, which applies to every matching path.

/*
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin

Step 3: Write .assetsignore before the first deploy

An .assetsignore file tells Wrangler which files in the assets directory never to upload. The binding docs say it uses the same format as .gitignore and sits in the root of the assets directory. They list no default exclusions, so if your site lives in the repo root, list your secrets, tooling and Git data yourself.

# never upload these, the assets directory is the repo root
.git
.env*
.wrangler
node_modules
wrangler.jsonc
worker.js
private-notes

We ran the test site with wrangler dev (Wrangler 4.163.0) and requested each path, once with this file and once without it.

PathWith .assetsignoreWithout it
/ and /blog/first-post200200
/api/health200 from the Worker200 from the Worker
/.env404200
/.git/config404200
/worker.js and /wrangler.jsonc404200
/private-notes/plan.md404200

The safer layout is a public/ folder as the assets directory, so nothing else is in reach. We publish from the repo root, so our .assetsignore is the line between public and private.

Step 4: Test locally, dry-run, then deploy

  1. Log in once. Run npx wrangler login.
  2. Run it locally. npx wrangler dev --config wrangler.jsonc and request the private paths. They should 404.
  3. Dry-run. npx wrangler deploy --config wrangler.jsonc --dry-run bundles everything without publishing.
  4. Deploy. npx wrangler deploy --config wrangler.jsonc, then confirm the output names my-site.
  5. Add your domain. Attach it under the Worker's domains settings, per Cloudflare's custom domains guide.

The dry-run line "Read N files from the assets directory" is not proof of what goes live. In our test it counted ignored files too. The local requests in step 2 are the real check.

Pro tip

Name the config file on every deploy. A deploy that finds no config file can fall back to defaults, and that is how a wrong folder gets published.

What went wrong for us

ProblemWhat happenedFix
Wrong folder publishedA deploy run without a config file published another project's folder, .git included, to a new workers.dev Worker. We deleted it within minutes--config and --dry-run every time
Duplicate URLs indexedAlways Use HTTPS was off, so http:// pages served 200 and Google indexed bothTurn on Always Use HTTPS
wrangler dev refused to startAn old global Wrangler did not support a newer compatibility dateUse npx wrangler@latest
AI answer engines blockedA firewall rule returned 403 to AI crawlersSee our Cloudflare field notes

Frequently asked questions

Should I use Cloudflare Pages or Workers for a new static site?

Both serve static files well. Workers static assets keeps static files and server code in one project and gives you the wider Workers feature set, so we use it for new sites. Cloudflare publishes a migration guide for moving from Pages.

Does Wrangler skip .git automatically?

Cloudflare's docs list no default exclusions for .assetsignore, and our local test served /.git/config when the file was missing. List .git yourself.

Do _headers and _redirects work on Workers?

Yes. Cloudflare's migration guide says both are supported natively in Workers static assets. Keep them in the assets directory.

Can I test a Workers site without deploying?

Yes. wrangler dev serves the same assets and Worker locally, and wrangler deploy --dry-run builds without publishing.

When to get help

If your site is slow to ship, leaks files it should not, or will not rank, tell us what you see or see what we build. Nactore is one partner that builds, ships, ranks and grows, measured on your growth.

Want to apply this to your business?

Book a free 30-minute call. We will tell you what we would do first.