js / css 改成每次重新驗證,部署完就不會再吃到舊檔 - #14
Merged
Merged
Conversation
檔名沒有內容雜湊,卻給了 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
There was a problem hiding this comment.
🟡 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 on lines
+22
to
+23
| /vendor/* | ||
| Cache-Control: public, max-age=604800, immutable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
public/_headers給/js/*與/css/*設了max-age=600,但檔名沒有內容雜湊。這表示部署完的十分鐘內,已經開過網頁的人拿到的仍是舊檔,而且瀏覽器連問都不問伺服器。今天被這件事咬了不只一次:修好的東西明明上線了,畫面還是舊行為,於是往程式碼裡找一個根本不存在的 bug。最後一次是「在 0G Storage 上查看」仍然連到
/file/<root>—— repo 裡早就沒有那段程式碼了。改法
/js/*/css/*max-age=600max-age=0, must-revalidate/vendor/*max-age=604800, immutable/index.htmlmax-age=0, must-revalidatemust-revalidate不等於不快取:檔案沒變時伺服器回 304,內容不重傳,只多一次很小的往返。這幾支檔案都只有二三十 KB。vendor/底下是釘死版本的第三方 bundle(合計約 1MB,內容不會變),改成長快取加immutable—— 比原本沒有規則時更好。🤖 Generated with Claude Code
https://claude.ai/code/session_015NBxaWtzqEX3i8NvoZEeq3
Generated by Claude Code