Workers - Control which routes invoke your Worker script for Single Page Applications
1y ago
Source
CloudflareWorkers - Control which routes invoke your Worker script for Single Page Applicationscloudflare.comFor those building Single Page Applications (SPAs) on Workers , you can now explicitly define which routes invoke your Worker script in Wrangler configuration. The run_worker_first config option has now been expanded to accept an array of route patterns, allowing you to more granularly specify when your Worker script runs. Configuration example: wrangler.jsonc { " name " : "my-spa-worker" , // Set this to today's date " compatibility_date " : "2026-07-03" , " main " : "./src/index.ts" , " assets " : { " directory " : "./dist/" , " not_found_handling " : "single-page-application" , " binding " : "ASSETS" , " run_worker_first " : [ "/api/*" , "!/api/docs/*" ] } } wrangler.toml name = "my-spa-worker" # Set this to today's date compatibility_date = "2026-07-03" main = "./src/index.ts" [ assets ] directory = "./dist/" not_found_handling = "single-page-application" binding = "ASSETS" run_worker_first = [ "/api/*" , "!/api/docs/*" ] This new routing control was done in partnership with our community and customers who provided great feedback on our public proposal . Thank you to everyone who brought forward use-cases and feedback on the design! Prerequisites To use advanced routing control with run_worker_first , you'll need: Wrangler v4.20.0 and above Cloudflare Vite plugin v1.7.0 and above
You might also wanna read
Cloudflare expands AI bot management tools with granular traffic controls for all customers
Cloudflare is celebrating the second "Content Independence Day" by expanding AI traffic management options for all website owners. Building
Workers - Simpler runtime types with @cloudflare/workers-types v5
Cloudflare·2d ago
AI Search - Manage AI Search sync jobs with Wrangler CLI
Cloudflare·3d ago
Workers - Work across multiple accounts with Wrangler auth profiles
Cloudflare·3d ago
Cache - Cache multiple versions of a URL with Vary
Cloudflare·3d ago
Cloudflare One - Hostname routing for Cloudflare Mesh
Cloudflare·3d ago

Comments
Sign in to join the conversation.
No comments yet. Be the first.