Last updated 5 years ago
Was this helpful?
Server 端總共有三種用時間來設定的 cache:
我們一樣使用 Node.js server,然後把回應改為以下:
res.setHeader("Expires", new Date("2025-02-10").toUTCString()) res.end('123');
只要 Expires 後面的參數是未來的時間都會進行緩存。(disk cache)
與 Expires 相反,只要是日期是過去式都會被快取。
res.setHeader("Last-modified", new Date("2005-02-10").toUTCString())
記得要用UTCString
max-age 單位為秒。
res.setHeader('Cache-Control', 'public, max-age=3');
超過三秒後要重新去取資料,所以可以一直按重新整理網頁,可以發現三秒後會重新要資料。
Copyprivate cache (瀏覽器快取) public cache (CDN )
private cache (瀏覽器快取) public cache (CDN )