具有 +150k 静态页面的应用程序的最佳方法?

具有 +150k 静态页面的应用程序的最佳方法?

问题描述:

我有一个集成了 NextJS 的 MERN 应用程序.第一次使用 NextJS,请耐心等待.我最初在任何地方都使用了 SSR (getServerSideProps).

I have a MERN app in which I have integrated NextJS. First time with NextJS so bear with me. I have initially used SSR everywhere (getServerSideProps).

要点:

  • 我有超过 150,000 个页面包含永远不会改变的静态内容.
  • 每周我都会添加大约 +100 个新页面.

我想这里的理想情况是使用 getStaticPropsgetStaticPaths,并且在最初构建这 150k 个页面后,每周构建新添加的页面并保持我已经建立的东西,因为它永远不会改变.

I guess the ideal situation here would be using getStaticProps and getStaticPaths and, after an initial build of those 150k pages, just build the new added pages every week and keep what I already have built as it is since it's never going to change.

我怎样才能做到这一点?我应该在这里使用 revalidate 吗?我一直在文档中阅读它,但我并不完全理解它.

How can I achieve this? Should I use revalidate here? I have been reading about it in the documentation but I don't completely understand it.

您可以使用 getStaticProps/getStaticPaths 来实现.

You could achieve that using getStaticProps/getStaticPaths.

revalidategetStaticProps 中用于 增量静态再生 - 在您想要更新现有生成的页面的情况下.在您的情况下,这不是您想要的,因为您提到生成的页面永远不会改变.

revalidate is used in getStaticProps for Incremental Static Regeneration - in cases where you'd want to update existing, generated pages. Which in your case is not what you want since you mentioned generated pages will never change.

要实现您想要的,并允许生成新页面,您可以使用 fallback:truefallback:blockinggetStaticPaths 中.

To achieve want you want, and allow new pages to be generated you can use fallback: true or fallback: blocking in getStaticPaths.

使用 fallback: true 构建时未生成的路径将在第一个请求时提供后备页面,而 Next.js 静态生成页面.完成此操作后,页面将从备用页面交换到实际的完整页面.

With fallback: true the paths not generated at build time will serve a fallback page on the first request while Next.js statically generates the page. When this is done the page will be swapped from the fallback page to the actual full page.

使用 fallback: blocks,构建时未生成的路径将等待 Next.js 生成 HTML,然后在完成后为页面提供服务.与 fallback: true 不同,由于没有回退,渲染会在页面生成之前被阻止.

With fallback: blocking, the paths not generated at build time will wait for the HTML to be generated by Next.js, then serve the page once that done. Unlike fallback: true, since there's no fallback the rendering gets blocked until the page is generated.

在这两种情况下,页面都会被添加到预渲染页面列表中.对同一路径的后续请求将提供预先生成的页面.

In both cases the page gets added to the list of pre-rendered pages. Subsequent requests to the same path will serve the pre-generated page.

请注意,next export 不支持这两个选项,以防万一.

Note that neither of these options is supported by next export, in case you depend on that.