Cloudflare tutor

A morning desk for Kotha · Gold Coast

· Australia/Brisbane · Lesson

Static assets: serve HTML, CSS, and images straight from a Worker

Workers Static Assets (the [assets] block, the ASSETS binding, not_found_handling, and run_worker_first)

What it is

Most of your Workers so far build every page in JavaScript: the HTML is written inside the code as one long string. Static assets are the other way. You keep ordinary files, such as index.html, style.css, logo.png, or a PDF, in a folder, point the Worker at that folder, and Cloudflare uploads the files alongside the Worker and serves them for you.

The config is a short block in wrangler.toml: [assets], then directory = "./public". When a request matches a file in that folder, the file is served without running your Worker code at all. Only when nothing matches does the request reach your Worker script, if you have one. With no script at all, an unmatched path simply returns 404 Not Found.

Three optional settings shape the behaviour. binding = "ASSETS" lets your code fetch a file itself with env.ASSETS.fetch(request), for example to add a header. not_found_handling = "404-page" serves your own 404.html, and "single-page-application" returns index.html for any unknown path, which suits React-style apps. run_worker_first = ["/api/*"] makes the Worker run before the files for just the paths you list. A .assetsignore file in the folder, written like .gitignore, keeps files you never want public from being uploaded.

Why it matters

It is free. Cloudflare's billing page says requests that return a static asset are free and unlimited, and storing the assets costs nothing extra. Only requests that run your Worker script count against your Workers requests.

It keeps the code small and the pages easy to edit. A page becomes a plain HTML file you, Gemini, or a bot can edit and preview in a browser, rather than text escaped inside a JavaScript string.

One catch for the free plan: paths you list in run_worker_first always run the Worker, so if you pass the daily free request limit, those paths get a 429 Too Many Requests response instead of falling back to the file. Keep that list to the few paths that genuinely need code, such as /api/*.

On your account

From your own setup, read only: this desk's Worker, cloudflare-tutor, has no [assets] block. Its wrangler.toml has the name, workers_dev = true, and two routes on cloudflare.kosan.xyz, and every lesson, including this one, lives as text inside worker.js, which is now about 150 KB of code that is mostly words.

A natural fit for you: a mostly static page on drkotha.com, such as a clinic information page or a printable patient handout, could be a public folder with index.html, style.css in the Clinic Bright colours, and the PDFs, deployed with wrangler deploy and served free. If it later needs a small form, a Worker script and run_worker_first = ["/api/*"] handle just that part, with the files still free.

Nothing was moved to static assets for this lesson. This desk only redeployed its own Worker, cloudflare-tutor, and did not change any DNS record, the AI News root redirect rule, ainews, aiweekly, or any other Worker.

Do this yourself

These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.

  1. In a new empty folder on your computer, create public/index.html with one line of text and a wrangler.toml containing name = "assets-practice", compatibility_date = "2026-11-05", and an [assets] block with directory = "./public", then run npx wrangler dev and open http://localhost:8787 to see the file served, and stop it with Ctrl+C without running wrangler deploy.