Start from Worker
Workers Sites require Wrangler ↗ — make sure to use the latest version.
If you have a pre-existing Worker project, you can use Workers Sites to serve static assets to the Worker.
-
Create a directory that will contain the assets in the root of your project (for example,
./public
) -
Add configuration to your
wrangler.toml
file to point to it. -
Install the
@cloudflare/kv-asset-handler
package in your project: -
Import the
getAssetFromKV()
function into your Worker entry point and use it to respond with static assets.
For more information on the configurable options of getAssetFromKV()
refer to kv-asset-handler docs ↗.
-
Run
wrangler deploy
ornpx wrangler deploy
as you would normally with your Worker project. Wrangler will automatically upload the assets found in the configured directory.