Skip to content

Static Assets

Kyushu supports bundling static files (HTML, CSS, JS, images) directly into your worker. At build time, kyu build embeds each asset into the worker binary and requests are served directly from memory at runtime.

  1. Add an [assets] section to your config

    kyushu.toml
    [assets]
    dir = "dist"

    The dir field points to the directory containing your static files, relative to the config file.

  2. Serve assets in your worker

    Use env.ASSETS.fetch to handle incoming requests:

    import type { ExportedHandler } from "kyushu-types";
    export default {
    async fetch(request, env) {
    return env.ASSETS.fetch(request);
    },
    } satisfies ExportedHandler;
  3. Build and run

    Terminal window
    kyu build kyushu.toml
    kyu run

You can instruct kyu build to generate pre-compressed variants alongside each asset:

[assets]
dir = "dist"
precompress = ["brotli", "gzip"]

When a browser sends Accept-Encoding: br or Accept-Encoding: gzip, Kyushu automatically serves the compressed variant with the appropriate Content-Encoding header - no runtime compression overhead.

env.ASSETS.fetch returns a WorkerResponse you can spread and override:

export default {
async fetch(request, env) {
const response = await env.ASSETS.fetch(request);
return {
...response,
headers: {
...response.headers,
"x-custom-header": "value",
},
};
},
} satisfies ExportedHandler;

Kyushu resolves asset paths with the following rules:

  • / resolves to /index.html
  • /about resolves to /about.html, then /about/index.html
  • Exact paths are matched first

The following headers are set automatically on every asset response:

HeaderValue
etagMD5 hash of the asset bytes
varyAccept-Encoding
last-modifiedFile modification time at build
cache-controlSet for .css, .js, .svg, .woff2
content-typeInferred from file extension
content-lengthSize of the served bytes
content-encodingbr or gzip when serving compressed asset
X-Content-Type-Optionsnosniff
Strict-Transport-Securitymax-age=31536000 ; includeSubDomains
Referrer-Policyno-referrer
X-Frame-OptionsDENY