IIS 預設啟用靜態文件緩存,瀏覽器二次請求返回 304 Not Modified,導致前端修改不生效,嚴重影響開發調試與內容更新。
Cache-Control: no-cacheCache-Controlno-cachecscript adsutil.vbs set w3svc/1/HttpHeaders/Cache-Control "no-cache"
# 其中 1 為網站 ID,全局則設 w3svc/HttpHeaders/Cache-Control
| 場景 | Header 設置 | 說明 |
|---|---|---|
| 開發調試 | Cache-Control: no-cache, no-store, must-revalidate | 強制每次向服務器驗證,不緩存任何內容 |
| 靜態資源長期緩存 | Cache-Control: public, max-age=31536000 | 一年過期,配合文件名哈希實現版本控制 |
| API 動態數據 | Cache-Control: private, no-cache | 僅瀏覽器緩存,中間代理不緩存,每次驗證 |
curl -I https://your-site.com/style.css
# 應包含
Cache-Control: no-cache
Expires/ETag/Last-Modified 實現精細緩存策略