Next.js 按需静态再生 [英] Next.js Static Regeneration on demand

查看:72
本文介绍了Next.js 按需静态再生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢 Next.js 的 增量静态再生.

I absolutely love Next.js's Incremental Static Regenration.

但是,我正在寻找一种方法来强制按需重新生成静态页面.理想情况下,通过一个命令,当我的源数据库中的数据发生变化时,我可以通过 API 调用触发该命令.

However, I'm looking for a way to force static pages regeneration on demand. Ideally via a command that I can trigger with an API call when the data in my source db change.

这个想法是在每次数据更改后重新生成每个页面一次.我可以通过在重新验证间隔后获取目标页面来强制执行 ISR 页面的重新生成,但我正在寻找一种方法不要在数据更改之前冗余地重新生成它们.

The idea is to regenerate each page just once after each data change. I could enforce ISR pages regeneration simply with fetching the target pages after their revalidation interval, but I'm looking for a way not to regenerate them redundantly until data changes.

任何想法是否可行以及如何?:-)

Any ideas if it's doable and how? :-)

推荐答案

目前(Next.js 10.1.3)没有对这个特性的原生支持,触发页面重新验证的唯一方法是使用一个间隔-基于 HTTP 请求.
然而 Next.js 团队正在
按需探索(通过 API 路由触发)重新验证(另见https://github.com/vercel/next.js/discussions/10721#discussioncomment-686)由于这是一个非常受欢迎的功能,因此将来可能会提供.
这里你可以找到按需重新验证页面的尝试,但它有严重警告,并且尚未准备好生产.

At the moment (Next.js 10.1.3) there is no native support for this feature, the only way to trigger a page revalidation is with an interval-based HTTP request.
However Next.js team is exploring on-demand (triggered via API route) revalidation (see also https://github.com/vercel/next.js/discussions/10721#discussioncomment-686) and since this is a highly requested feature may be avaible in the future.
Here you can find an attempt for revalidate pages on demand, but it has serious caveats and is not production ready.

来源:
按事件更新静态页面
超级增量静态再生

这篇关于Next.js 按需静态再生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆