[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Page routing is always a serverless function

123 views · 1 like · 2 posts


cohen-tal (@cohen-tal) · 2024-08-06

Hello!

I deployed my hobby Nextjs (latest version) to vercel, and noticed i keep getting "this function has timed out" error. 
After inspecting the logs, i noticed that every page route (using the Link component / home page when first entering the website) request is actually a serverless function, even though some pages are marked with "use client" and have no API calls to the api route in my app. Is this the default behavior?

How can i stop every single page route request from being a serverless function as its crashing my website when cold starting my backend server as it is also hosted on a free tier and takes about 15-20 seconds on average to spin back up.


Pauline P. Narvas (@pawlean) · 2024-08-06 · ♥ 1

Hi, @cohen-tal!

To prevent every page route request in your Next.js app on Vercel from becoming a serverless function, you need to use **Static Site Generation (SSG)** with `getStaticProps` or **Client-Side Rendering (CSR)** with data fetching inside `useEffect`, avoiding methods like `getServerSideProps` or `getInitialProps` that trigger **server-side rendering (SSR)**.

This minimizes reliance on serverless functions, mitigating the "function timeout" errors caused by backend cold starts. You can also verify your `next.config.js` and Vercel deployment settings to avoid any misconfigurations that enforce SSR.

Cross-posting some recommended reading:

- [Next.js Static Generation](https://nextjs.org/docs/basic-features/data-fetching/get-static-props)
- [Next.js Server-Side Rendering](https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props)
- [Next.js Client-Side Data Fetching](https://nextjs.org/docs/basic-features/data-fetching#fetching-data-on-the-client-side)
- [Vercel Next.js Deployment](https://vercel.com/docs/concepts/deployments/overview)
- [Vercel Cold Start Guide](https://vercel.com/docs/concepts/functions/edge-caching#cold-starts)
- [Next.js Examples](https://github.com/vercel/next.js/tree/canary/examples)