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 script to return a response under all requests headed for /api/
. Otherwise, the Worker script will pass the incoming request through to the asset binding. In this case, because a Worker script is only invoked when the requested route has not matched any static assets, this will always evaluate not_found_handling
behavior.
For the various static asset routing configuration options, refer to Routing.