---
title: "Static assets"
---

> Documentation Index
> Fetch the complete documentation index at: https://workerd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 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](https://developers.cloudflare.com/workers/static-assets/)
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 `/`.

```text title="public/_headers"
/*
  X-Served-By: workerd
```

```text title="public/_redirects"
/home / 301
```

```html title="public/index.html"
<!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>
```

```jsonc title="wrangler.jsonc"
{
  "name": "static-assets",
  "compatibility_date": "2026-01-01",
  "assets": { "directory": "./public" }
}
```

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

```sh
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](https://workerd.dev/docs/cloudflare-compat/#services).

Source: https://workerd.dev/docs/services/static-assets/index.mdx
