Skip to content

Static assets

Static assets serve the files of a directory, with a Worker or without one. workerd reads each file from the directory when a request asks for it, so a change to a file shows at once, without a restart. In a cluster, each instance serves the files from its own copy of the project. Read the Cloudflare Static Assets documentation for the routing rules and the configuration.

Example

The Static assets example serves an HTML file from the public directory without a Worker. A _headers file adds a response header. A _redirects file redirects /home to /.

public/_headerstext
/*
  X-Served-By: workerd
public/_redirectstext
/home / 301
public/index.htmlhtml
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>workerd static assets</title>
  </head>
  <body>
    <h1>This file is served by workerd.</h1>
  </body>
</html>
wrangler.jsoncjsonc
{
  "name": "static-assets",
  "compatibility_date": "2026-01-01",
  "assets": { "directory": "./public" }
}

Static assets are experimental, so they need --experimental:

npx workerd serve --experimental ./static-assets/wrangler.jsonc
curl -i http://localhost:8787/
curl -i http://localhost:8787/home

Configuration

The assets block accepts directory, binding, html_handling, not_found_handling, run_worker_first, and base_path. Any other key stops startup. Without main, a project cannot set binding or a field that needs a Worker, such as vars or exports.

workerd reads _headers, _redirects, and .assetsignore when it starts. To apply a change to one of these files, restart workerd, or run it with --watch.

Differences from Cloudflare

  • workerd does not compress a response, and it has no edge cache. If clients need compression or a cache, put a proxy in front of workerd.
  • The ETag is a hash of the path, the size, and the modification time of the file, not of its content.
  • workerd answers a Range request with the whole file and status 200.
  • workerd follows each symbolic link in the directory, even a link to a file outside it.

See also Cloudflare compatibility.

Type to search…

↑↓ navigate↵ selectEsc close