Cloudflare Workers skip fetch handler when static assets match the request
A developer discovered that redirect logic written inside a Cloudflare Worker's fetch handler never executed because static asset requests are served directly at the edge, bypassing the Worker entirely. By default, Cloudflare only invokes the Worker script for requests that do not resolve to a file in the assets directory, meaning the handler effectively only caught 404s. The issue can be confirmed by requesting a non-existent path — if that triggers the redirect while real pages do not, the Worker is being skipped for asset-backed URLs. The recommended fix is to use Cloudflare's Redirect Rules, found under Rules in the dashboard, which run earlier in the traffic sequence than Workers and are free on all plans. Forcing the Worker to run before the asset lookup is an alternative but is considered wasteful for simple redirects that do not require per-request logic.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in