如何在不重建具有 150k 静态页面的应用程序的情况下添加新页面?

发布于 2025-01-11 10:23:06 字数 413 浏览 3 评论 0 原文

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

要点:

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

我想这里的理想情况是使用 getStaticPropsgetStaticPaths,并且在初始构建这 150k 页面之后,每周构建新添加的页面并保留我已有的页面已经按原样建立,因为它永远不会改变。

我怎样才能实现这个目标?我应该在这里使用revalidate吗?我一直在文档中阅读有关它的内容,但我并不完全理解它。

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).

Key points:

  • I have over 150,000 pages with static content that it's never going to change.
  • Every week I add around +100 new pages.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2025-01-18 10:23:06

这可以通过 getStaticProps/getStaticPaths 来实现。您必须使用 后备: truegetStaticPaths 中的 fallback: 'blocking'

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

使用 fallback: 'blocking',构建时未生成的路径将等待 Next.js 生成 HTML,然后在完成后提供页面。与 fallback: true 不同,由于没有后备,渲染会被阻止,直到生成页面,类似于服务器端渲染期间发生的情况。

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

next export 不支持这些选项,以防您依赖它。


请注意,revalidategetStaticProps 中用于 增量静态重新生成 - 如果您想要更新现有的生成页面。既然您提到生成的页面永远不会改变,那么就不需要使用revalidate

That can be achieved with getStaticProps/getStaticPaths. You'll have to use fallback: true or fallback: 'blocking' in getStaticPaths.

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.

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's done. Unlike fallback: true, since there's no fallback the rendering gets blocked until the page is generated, similar to what happens during server-side rendering.

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.

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


Note that revalidate is used in getStaticProps for Incremental Static Regeneration - in cases where you'd want to update existing, generated pages. Since you mentioned generated pages will never change, then there's no need to use revalidate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文