Next.js Discord

Discord Forum

Is each route its own function?

Unanswered
Jersey Wooly posted this in #help-forum
Open in Discord
Jersey WoolyOP
So when building Next.js and deploying to Vercel, we can see an overview of what route gets build to run on what runtime.

What I don't understand is how it's bundled.

- So if I have 10 routes on NodeJS runtime, is that 1 serverless function or 10?
- Is there any difference between between bundling route handlers, server components, routes, server actions, etc.?

Docs only share that it "will be bundled into the fewest number of Serverless Functions possible" https://vercel.com/docs/functions/serverless-functions/runtimes#functions-created-per-deployment which isn't much information.

14 Replies

well i have made heaps of pages and no issue, but i think it optimisms nextjs very well (i also think it is decently linked with lamda size limit)
Jersey WoolyOP
yeah, I'm not worried about optimizing, I'm more like interested in how it works. And also it might be a good thing to know if I ever need to debug or optimize something.
Hey @Jersey Wooly
I cant speak for how the new app dir handles things
but with the pages directory, each page is its own serverless function
and same for the apis
the build process will try to create a single bundle for shared javascript code
like libraries which are used by each page
@Jersey Wooly asked to Vercel earlier but didn't get much info either
It might have internal heuristics to pick the right number
so from code point of view, each page or API route is its own application
but from infra point of view there may or may not be bundled depending on your host, as far as I can tell
Jersey WoolyOP
Thanks to both answers @Eric Burel and @linesofcode
Yeah I was afraid that it’s gonna be a black box on Vercel side.
I mean not that it does matter now. But would’ve been interesting to know