Lazy routers?

Hi, does hono support lazy routers? I made a really huge router with some heavy dependencies and now I'm getting spikes on cold starts
8 Replies
Memtooth
Memtooth2mo ago
Not out of the box, but maybe you can try async imports within a “router of routers”.
Gary, el Pingüino Artefacto
I don't quite get the idea
.get("/some-route", async (c) => {
if (!someRouteCode) {
someRouteCode = await import("./some-route-code")
}

return someRouteCode(c)
})
.get("/some-route", async (c) => {
if (!someRouteCode) {
someRouteCode = await import("./some-route-code")
}

return someRouteCode(c)
})
Something like this?
Memtooth
Memtooth2mo ago
Yes, I was thinking of request() https://hono.dev/docs/api/hono#request
App - Hono - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Gary, el Pingüino Artefacto
To be honest, I don't get how is this method usefull in this context May be I'm missing something?
Arjix
Arjix2mo ago
Hono technically supports any kind of router, since you can provide a custom implementation for a router But I don't know if making a lazy router is a great idea
Memtooth
Memtooth2mo ago
Agree. Cold starts implies lambdalith -- it's probably better handled at the l7 layer (load balancer, api gw, cdn, etc).
Arjix
Arjix2mo ago
@Gary, el Pingüino Artefacto just in case, have you tried using hono/quick? https://hono.dev/docs/api/presets#hono-quick
Gary, el Pingüino Artefacto
I'm only know the basic of hono, so no. I'm very new. I'll give it a shoot. Thanks dude!

Did you find this page helpful?