serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.46k stars 457 forks source link

getStaticPaths + getStaticProps with multiplexing/batching? #732

Open panbanda opened 3 years ago

panbanda commented 3 years ago

I would like to find a solution where we don't have to send individual requests to get the props once it has loaded the paths. My current situation is a site that has 400 articles that are translated totaling 1200. In order to bake them getStaticPaths loads the slugs and then passes them to getStaticProps which loads them one by one. This obviously has many issues.

I currently have multiplexing for graphql queries, I can also build in my own api for rendering the articles, but I think the way getStaticProps works (being isometric?) is that it should load one article. So is it worth exploring adding another method to bulk load for SSR?

dphang commented 3 years ago

Sorry, I'm not quite sure what the ask is here, could you please clarify what you'd like to change exactly? Yes, I think getStaticProps is called once per page, even for Vercel?

panbanda commented 3 years ago

Sorry @dphang I am actually wondering if there is a way to implement something like DataLoader for the getStaticProps because the number of requests is going to dramatically increase as we add languages. Otherwise i'll just have to avoid making them static pages for the sake of build times.

panbanda commented 3 years ago

An example would be a site I worked on recently had around 10,000 english articles. They wanted to branch out to 5 languages and have everything translated. That would mean 50k requests each build. Instead I could load 1k articles at a time and build the pages using something like dataloader.

fezproof commented 3 years ago

This seems like a great candidate for Incremental Static Generation! See here https://nextjs.org/docs/basic-features/data-fetching#incremental-static-regeneration !

panbanda commented 3 years ago

@fezproof would you look at that... ✨