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.
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.