staleTimes

staleTimes 是一項實驗性功能,可將頁面片段快取在 客戶端路由快取 (Client Router Cache) 中。

您可以啟用此實驗性功能,並透過設定實驗性的 staleTimes 標誌來提供自訂的重新驗證時間:

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    staleTimes: {
      dynamic: 30,
      static: 180,
    },
  },
}

module.exports = nextConfig

staticdynamic 屬性對應於不同類型 連結預取 (link prefetching) 的時間週期(以秒為單位)。

  • dynamic 屬性用於頁面既非靜態生成也未完全預取的情況(例如使用 prefetch={true})。
    • 預設值:0 秒(不進行快取)
  • static 屬性用於靜態生成的頁面,或當 Linkprefetch 屬性設為 true 時,或呼叫 router.prefetch 時。
    • 預設值:5 分鐘

須知事項:

您可以在 這裡 了解更多關於客戶端路由快取的資訊。

版本歷史

版本變更內容
v15.0.0dynamicstaleTimes 預設值從 30 秒更改為 0 秒。
v14.2.0實驗性 staleTimes 功能首次引入。

On this page