How to reduce Next.js build times??

a year ago

Takes about 5-8 minutes to build and deploy now which is annyoing.
Also increases every week

0 Replies

a year ago

030a956c-af55-4f43-a7de-5bdff4ea474b


a year ago

im not using any configuration btw, just default nix packs


a year ago

Besides code-wise and file excluding optimization I don't think u can do much


a year ago

But iirc railway caches build so your next build may be faster (I can be wrong on this one)


a year ago

why are vercel builds so much faster though?


a year ago

vercel made next


a year ago

Well, they literally created nextjs


a year ago

And use "specific technologies" for it


a year ago

in turn, railway is not hyper optimized for any one specific type of app


a year ago

this is not very helpful tbh


a year ago

i would appreciate if you woulr rather direct me towards resources towards optimizing nixpacks for next.js


pepijnPRO

a year ago

Just to chip in, in my case Vercel is actually slower in a fresh build, haha (using Next 14). But in Railway you have overhead which Vercel does not have? (or maybe less) due to the creating and publishing the image is to registry after which it can be deployed.


pepijnPRO

a year ago

Additionally publishing the image (2.6GB) took around 3-4 mins


a year ago

Optimizing nixpacks is not the way to go. Instead, creating your own dockerfile will likely be faster. We cannot help you with that here as it does not fall under the scope of “Platform Help”


a year ago

you’ll have to research for yourself


a year ago

Thanks for this direction! Will try this 🙂


a year ago

thanks again <@744739465045737623>


a year ago

made my own optimized dockerfile and build time cut by 50%



pepijnPRO

a year ago

Thanks, also interesting going this way reduced idle memory usage with 80%


AnonymousTRIAL

a year ago

yeah docker is not comparable to railway internal system to build stuff, docker is faster easier and uses less memory


a year ago

docker is used to build the final image no matter what build system you choose to use, so that's not completely correct


a year ago

Yep! My memory usage decreased significantly <@823198403668213760>

Build times went from 12min -> 6min
Memory usage also cut in half or so meaning costs are lower


a year ago

Noticed the default nixpacks docker image for node is ubuntu instead of something like node-alpine?

Any reason why?
Cc <@539512869780455445>


a year ago

so apt packages can be installed


a year ago

Just throwing this in here:



a year ago

imo it's better than next.js , you get a very similar benefit (SSR, React full stack)


a year ago

it runs well anywhere (including Railway.app)


a year ago

mem cost is great (idles about 25mb)


a year ago

my build time is about 2 minutes


pepijnPRO

a year ago

For comparison, after changing the NextJs build with the setup per above (including building NextJs with standalone option), my builds are also about 2 minutes for an ecommerce site connected to MedusaJs and Strapi. Memory usage in idle is around 40Mb.


AnonymousTRIAL

a year ago

fully agree on this and if you deploy it on cloudflare you will see blazing speeds never seen before


AnonymousTRIAL

a year ago

global servers across 200 countries, can handle insane traffic, 10x cheaper than almost anyone else


a year ago

did you forget you where in the railway server? we shill railway here


How to reduce Next.js build times?? - Railway Help Station