The docs are a little confusing on the Static Assets Workers, maybe I'm misreading them but they see

The docs are a little confusing on the Static Assets Workers, maybe I'm misreading them but they seem to contract themselves.

If you read https://developers.cloudflare.com/workers/static-assets/routing/ it says:

When a request invokes a Worker with assets:

If a request is found with a matching path to the current route requested then that asset will always be served.


I tested it, and if a static asset is matched, it's returned, else my Worker's fetch is invoked. Makes sense. Then I got confused by the binding example on https://developers.cloudflare.com/workers/static-assets/binding/:

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    if (url.pathname.startsWith("/api/")) {
      // TODO: Add your custom /api/* logic here.
      return new Response("Ok");
    }
    // Otherwise, serve the static assets.
    // Without this, the Worker will error and no assets will be served.
    return env.ASSETS.fetch(request);
  },
};


But I don't think that's true / the final return won't ever be hit if a static asset is found, it would just never call the worker (e.g. you have public/blog.html, and /blog is hit, it will just return the static asset and not call the worker). Am I missing something? It feels like the final "return" should really be a 404? Which I think technically it would return anyway but to me at least it's a bit misleaading as for assets that exist, it'd never hit the worker anyway
Was this page helpful?