Configuration and binding
Configuring a Worker with assets requires specifying a directory and, optionally, an assets binding, in your Worker’s wrangler.toml
file. The assets binding allows you to dynamically fetch assets from within your Worker script (e.g. env.ASSETS.fetch()
), similarly to how you might with a make a fetch()
call with a Service binding.
Only one collection of static assets can be configured in each Worker.
The folder of static assets to be served. For many frameworks, this is the ./public/
, ./dist/
, or ./build/
folder.
Configuring the optional binding gives you access to the collection of assets from within your Worker script.
In the example above, assets would be available through env.ASSETS
.
Parameters
request: Request
Pass a Request object, URL string, or URL object. Requests made through this method havehtml_handling
andnot_found_handling
configuration applied to them.
Response
Promise<Response>
Returns a static asset response for the given request.
Example
Your dynamic code can make new, or forward incoming, requests to your project’s static assets using the assets binding.
Take the following example that configures a Worker to return a response under all requests headed for /api/
. Otherwise, the Worker will fallback to returning static assets.
For the various static asset routing configuration options, refer to Routing.