Skip to content
Miniflare
Visit Miniflare on GitHub
Set theme to dark (โ‡ง+D)

๐ŸŒ Workers Sites

Enabling Sites

Workers Sites can be enabled by specifying a path to serve files from. You can optionally specify glob patterns to include/exclude. If you specify both include and exclude options, only include will be used and exclude will be ignored:

wrangler.toml
[site]
bucket = "./public"
# Below options are optional
include = ["upload_dir"]
exclude = ["ignore_dir"]
const mf = new Miniflare({
sitePath: "./public",
// Below options are optional
siteInclude: ["upload_dir"],
siteExclude: ["exclude_dir"],
});

The following worker will now serve static files from the ./public directory. Note that you'll need a build step to bundle @cloudflare/kv-asset-handler. See ๐Ÿ›  Builds for more details:

import { getAssetFromKV } from "@cloudflare/kv-asset-handler";
addEventListener("fetch", (event) => {
event.respondWith(getAssetFromKV(event));
});

Internal Details

When you enable Workers Sites, a read-only KV namespace, bound to __STATIC_CONTENT, is created using the file system (without key sanitisation) as its storage. Each entry in the bound __STATIC_CONTENT_MANIFEST object contains a magic prefix that disables edge caching. This means the most up-to-date file are always loaded from disk. Miniflare also binds this object to the __STATIC_CONTENT_MANIFEST text module.