DevOps2 min read

A static site on Cloudflare Workers in five minutes

No server, no FTP and usually no bill. Wrangler config, cache headers, redirects and a custom 404 page.

workers

Illustrative photo: Unsplash

This blog is written in WordPress, but you are reading it as plain HTML files served from Cloudflare Workers. For a site that does not need a database on every visit, this is the fastest and cheapest route: the files sit at the edge of the network, close to the reader.

Configuration

You need one file. The [assets] section says which folder to serve — you do not have to write any Worker script at all.

name = "my-site"
compatibility_date = "2026-10-01"

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

The not_found_handling = "404-page" option returns your own 404.html with a 404 status for missing URLs instead of an empty response.

Deploy

npx wrangler login     # once, opens the browser
npm run build
npx wrangler deploy

A few seconds later the site is live at my-site.<account>.workers.dev. If your DNS is on Cloudflare, attaching a custom domain is one click in the dashboard.

Caching and headers

A _headers file in the build folder sets headers per path. Files with a hash in the name can be cached “forever”, HTML only briefly, so a new version shows up right away.

/assets/*
  Cache-Control: public, max-age=31536000, immutable

/*.html
  Cache-Control: public, max-age=300

Redirects

Changed an article’s URL? A _redirects file handles it without code, and search engines move the ranking to the new address.

/old-url/   /new-url/   301

What it costs

On the free plan, requests for static files alone do not count towards the Worker invocation limit. For a blog or a business card site the bill is usually zero. Limits and pricing change, so check the current docs before a bigger project.

When not to go static Live comments, logins, a cart with stock levels — those need a backend. Then the same Worker can get code and a D1 database, but that is a topic for another article.

STOS

A blog about front-end, DevOps and tooling

Built on WordPress: custom block theme, Polylang, Yoast SEO. See the WordPress admin in Playground ↗

STOS is a fictional blog — a portfolio concept project. The author and content are samples.