Skip to content

js / css 改成每次重新驗證,部署完就不會再吃到舊檔 - #14

Merged
k66inthesky merged 1 commit into
mainfrom
claude/0g-tech-competition-deploy-lv08or
Sep 10, 2026
Merged

k66inthesky merged 1 commit into
mainfrom
claude/0g-tech-competition-deploy-lv08or

Conversation

@k66inthesky

Copy link
Copy Markdown
Contributor

問題

public/_headers 給 /js/* 與 /css/* 設了 max-age=600,但檔名沒有內容雜湊。這表示部署完的十分鐘內,已經開過網頁的人拿到的仍是舊檔,而且瀏覽器連問都不問伺服器。

今天被這件事咬了不只一次:修好的東西明明上線了,畫面還是舊行為,於是往程式碼裡找一個根本不存在的 bug。最後一次是「在 0G Storage 上查看」仍然連到 /file/<root> —— repo 裡早就沒有那段程式碼了。

改法

路徑 之前 現在
/js/* /css/* max-age=600 max-age=0, must-revalidate
/vendor/* (沒有規則) max-age=604800, immutable
/index.html max-age=0, must-revalidate 不變

must-revalidate 不等於不快取:檔案沒變時伺服器回 304,內容不重傳,只多一次很小的往返。這幾支檔案都只有二三十 KB。

vendor/ 底下是釘死版本的第三方 bundle(合計約 1MB,內容不會變),改成長快取加 immutable —— 比原本沒有規則時更好。

🤖 Generated with Claude Code

https://claude.ai/code/session_015NBxaWtzqEX3i8NvoZEeq3


Generated by Claude Code

檔名沒有內容雜湊,卻給了 max-age=600 —— 部署完的十分鐘內,已經開過網頁的人
拿到的仍是舊檔,而且瀏覽器連問都不問伺服器。

今天被這件事咬了不只一次:修好的東西明明上線了,畫面還是舊行為,於是往程式碼
裡找一個根本不存在的 bug。最後一次是「在 0G Storage 上查看」仍然連到已經被
刪掉的 /file/<root> —— repo 裡早就沒有那段程式碼了。

改成 max-age=0, must-revalidate。這不等於不快取:檔案沒變時伺服器回 304,
內容不重傳,只多一次很小的往返;這幾支檔案都只有二三十 KB。

vendor/ 底下是釘死版本的第三方 bundle(合計約 1MB,內容不會變),改成長快取
加 immutable,反而比原本沒有規則時更好。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015NBxaWtzqEX3i8NvoZEeq3
@k66inthesky
k66inthesky marked this pull request as ready for review September 10, 2026 07:25
Copilot AI lite review requested due to automatic review settings September 10, 2026 07:25
@k66inthesky
k66inthesky merged commit c769e0e into main Sep 10, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

/vendor/* 目前仍是無版本/無雜湊檔名卻設定長快取+immutable,未來更新 vendor 檔時會再次導致使用者長時間吃到舊檔。

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

此 PR 調整 public/_headers 的靜態資源快取策略,避免因 js/css 檔名未含內容雜湊而在部署後一段時間內仍被瀏覽器使用舊檔,造成前端行為與已部署版本不一致。

Changes:

  • 將 /js/*、/css/* 的 Cache-Control 從 max-age=600 改為 max-age=0, must-revalidate,強制每次重新驗證。
  • 新增 /vendor/* 的快取規則:max-age=604800, immutable(長快取)。
  • 保持 /index.html 仍為 max-age=0, must-revalidate。
File summaries
File Description
public/_headers 更新 js/css 的重新驗證策略,並新增 vendor 長快取規則以改善資源更新一致性與效能
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread public/_headers
Comment on lines +22 to +23
/vendor/*
Cache-Control: public, max-age=604800, immutable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants