{/* The content of this doc is shared between the app and pages router. You can use the
component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
您可以为启用了 ISR 的页面,在 Cache-Control 头部中指定一个自定义的 stale-while-revalidate 过期时间供 CDN 使用。
打开 next.config.js 并添加 expireTime 配置:
module.exports = {
// one hour in seconds
expireTime: 3600,
}现在,当发送 Cache-Control 头部时,过期时间将根据具体的重新验证周期进行计算。
例如,如果某个路径的重新验证时间为 15 分钟,且过期时间为一小时,那么生成的 Cache-Control 头部将是 s-maxage=900, stale-while-revalidate=2700,这样它可以在比配置的过期时间少 15 分钟的时间内保持陈旧状态。