0

I have created really big project with page that have over 800,000 variants. In my current React project I just access the url parameter on www.mywebsite.com/my_page/:id and I use useEffect. Here is simplified example:

  url= `${apiAddress}/my_route?id=${props.match.params.id}`
  useEffect(() => {
    axios({
      method: "get",
      url: url,
      timeout: 60 * 4 * 1000, // Let's say you want to wait at least 4 mins
      headers: {
        Authorization:......,
        "Access-Control-Allow-Origin": "*",
      },
    })
      .then((res) => {
        setResults(res.data);
      })
      .catch((err) => {
       //some error handling....
      });
  }, [url]);

So this is working pretty fine. The situation is that I fetch here the response every time I open the pages but the information for every single ID is the same for at least one year. So there aren't any changes for at least for a year. It usually takes 5-6 seconds to load the page with the info and I am wondering is it possible with Next.js pre-fetching to pre-build all the pages and to take nothing to load them? I know number 800,000 is quite big so that's why I am asking. If I use getStaticProps I am able to do similar stuff for much less number of ids but if it tooks 5 seconds to fetch data for 1 page and they are 800,000 does this mean that I would have to wait for build 800,000x5 = 46 days?

Thanks in advance!

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Borislav Stefanov
  • 533
  • 3
  • 15
  • 38
  • 1
    https://nextjs.org/docs/basic-features/data-fetching#incremental-static-regeneration, https://vercel.com/docs/concepts/next.js/incremental-static-regeneration -- pass `revalidate: 3.154e+7` to re-generate a page at most once every year. – brc-dd Nov 15 '21 at 10:47
  • but for 800,000 pages how much time will build get? – Borislav Stefanov Nov 15 '21 at 10:52
  • It won't generate all the pages during build. Read the docs, you'll understand. – brc-dd Nov 15 '21 at 10:53
  • ahhh I see. Thanks a lot, this is what I was asking for. – Borislav Stefanov Nov 15 '21 at 10:54
  • 1
    Does this answer your question: [How to add new pages without rebuilding an app with +150k static pages?](https://stackoverflow.com/questions/66036558/how-to-add-new-pages-without-rebuilding-an-app-with-150k-static-pages)? Note that you don't have to use Incremental Static Regeneration if the pages aren't going to change. – juliomalves Nov 15 '21 at 13:11

0 Answers0