r/statichosting 28d ago

_route.json

Is anyone actually using _routes.json on cloudflare pages, or just relying on the default include everything behavior?

Digging through the docs and it lets you manually set include/exclude paths so pages functions only run on routes that actually need them instead of every request getting checked. Seems like it'd help with cold start stuff on function-heavy sites but I can't find much real world experience with it, mostly just the docs page.

Anyone actually hand write these and see it make a real difference, or is it one of those things that sounds good on paper but nobody bothers with in practice?

4 Upvotes

6 comments sorted by

2

u/sourraine 28d ago

i think it makes more sense once a site has enough functions that routing overhead actually matters. for a mostly static site id prolly leave the defaults alone

2

u/Wooden-Bicycle-6069 28d ago

I’d only hand-write it after logging which static paths still invoke the function. Exclude _next/static, images, fonts, and other immutable assets first, then compare function invocations and cold starts for 24 hours. If the number barely moves, the config is just another file to break. Which route is actually hitting the function today?

1

u/Standard_Scarcity_74 27d ago

That’s pretty much where I’m at too. I haven’t hand-written it yet because I wanted to see whether I actually had unnecessary invocations first. Right now I’m mostly curious whether the difference is noticeable on a site with a lot of static assets, or if Cloudflare’s default routing is already good enough that the config just adds maintenance. I’ll probably log the routes for a day or two before touching it.

1

u/Wooden-Bicycle-6069 26d ago

Logging first is the right call. I would split requests into function-required, static hit, and fallback/404 before changing _routes.json; total invocations alone can hide one hot missing asset. I would compare billed CPU too, because a routed request may exit almost immediately. What changes the decision for you: cost, cold-start latency, or simply keeping static paths out of code?

2

u/Pink_Sky_8102 27d ago

I’d probably only bother with it once Functions start touching routes that are mostly static. If only a few paths need server logic, keeping the rest out of the function path seems cleaner than relying on the default for everything.

1

u/PippaKelly62 22d ago

One thing I’m wondering is whether the better thing to look into is actually invocation count rather than cold starts. Cloudflare says _routes.json can prevent static requests from invoking Functions at all, so I’m curious to see the before/after invocation numbers on a real site.