Next.js Discord

Discord Forum

precompile routes

Unanswered
Netherland Dwarf posted this in #help-forum
Open in Discord
Netherland DwarfOP
Hiya guys, would love to know what is your approach on compiling all pages in a prod env? Are you running a script that makes a request to all endpoints in order to precompile before your EKS sets readiness? Is there an alternative way to do that using nextjs? I saw a thread about it, but there's no solution https://github.com/vercel/next.js/issues/6554 thanks.

15 Replies

@joulev You are not supposed to run next dev in prod. You are supposed to run next build then next start
Netherland DwarfOP
We are not running dev in prod, let me rephrase my question, I might have mistaken something here 😄
@Netherland Dwarf We are not running dev in prod, let me rephrase my question, I might have mistaken something here 😄
Well the linked discussion is literally titled “Nextjs dev compiles each page at request time… why?”
Netherland DwarfOP
You are right, I confused few different things, let me go over it again, and see if it is relevant. thanks joulev!
@Netherland Dwarf We are not running dev in prod, let me rephrase my question, I might have mistaken something here 😄
If your page loads slow in prod, that’s because the page is being dynamically rendered, which means while the bundle files are already built during next build, the data required to populate the page is only fetched on request
To make it fetch the data at build time, use static rendering
Netherland DwarfOP
The issue im facing is, ELB sometimes gives 503 when redeploying a new website pod, which made me think it is nextjs compile time, but it is indeed not making any sense since it is prod build
Hmm what is ELB and could you clarify on the 503 part?
Netherland DwarfOP
Yes, so when I run my CD github action to deploy a new version of the website, I use rolling update in order to have X amount of pods up before closing the old pods in the EKS environment. the ELB (elastic load balancer) routes users to the new pods and some of the users sometime get 503 when I do that
Makes me think the readinessProbe is bad (it is what tells the ELB to start routing to those new pods)
Oh I see… well as you probably guessed, I’m not at all experienced with self-hosting nextjs like this so I’m sorry I can’t help here
No idea what all these terms are
Netherland DwarfOP
No probs! thanks joulev!