[Incremental Static Regeneration]
ISR目的是讓動態的路由可以針對部分路由生成靜態html,且可透過設定來刷新這些靜態html.
Build time會先透過generateStaticParams返回路由參數列表並透過此參數列表產生靜態html.
然後用戶進入url時,會檢查路由參數是否存在於build time產生的html,
用戶第一次進入,若有設定revalidate,cache control內會有cache-control: s-maxage=xxx, stale-while-revalidate=xxx表示快取逾時秒數,
  • 有revalidate設定且未逾時就會返回http status 304與遊覽器緩存的html內容
  • 有revalidate設定且逾時了就會返回http status 304與遊覽器緩存的html內容,但server端會在背景重新產生html,然後當下一次請求進入(ex:重整頁面)時,因為etag的hash變了,所以會返回新的html,但若是用route轉導則不會更新內容的(rsc payload不會改變)
  • 沒有revalidate設定就會看dynamicParams設定,為true時就會動態產生html並返回該html,為false就會轉跳到404頁面
PS:Cloudflare not support ISR, only can test on local build & local start
CURL範例(revalidate=60)
(檢驗"ETag")未逾時的請求返回304,故使用上次緩存的html
img
(檢驗"ETag")已逾時的請求仍返回304,仍使用上次緩存的html,但服務器會在背景重新產生該html,response header有標記已過時
img
已重新產生html,故返回該html並更新"ETag"
img
Id: 1, revalidate:(60s)
(Server刷新時間)Timestamp: 1759370984212