NextJS中文文档 - StaleTimes
staleTimes
是一个实验性功能,它允许在客户端路由器缓存中缓存页面段。
你可以通过设置实验性的 staleTimes
标志来启用此功能并提供自定义的重新验证时间:
js
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
staleTimes: {
dynamic: 30,
static: 180,
},
},
}
module.exports = nextConfig
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
static
和 dynamic
属性对应基于不同类型的链接预取的时间周期(以秒为单位)。
dynamic
属性用于既不是静态生成也不是完全预取的页面(例如,使用prefetch={true}
)。- 默认值:0 秒(不缓存)
static
属性用于静态生成的页面,或者当Link
上的prefetch
属性设置为true
时,或者当调用router.prefetch
时。- 默认值:5 分钟
须知:
你可以在这里了解更多关于客户端路由器缓存的信息。
版本历史
版本 | 变更 |
---|---|
v15.0.0 | dynamic staleTimes 默认值从 30 秒变为 0 秒。 |
v14.2.0 | 引入实验性的 staleTimes 。 |