Repository navigation
perf: ハッシュ付きの Astro アセットをブラウザに長期キャッシュさせる - #822
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
blog | 1163243 | Commit Preview URL Branch Preview URL |
Nov 20 2026, 03:53 AM |
This branch has not been deployed
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.
Summary
public/_headersを追加し、ファイル名にハッシュを含む Astro のアセット(/_astro/*)にCache-Control: public, max-age=31536000, immutableを付けました。これまでは CSS や画像も含めてすべてpublic, max-age=0, must-revalidateだったため、2 回目以降のページ表示でも、ブラウザは表示を止める CSS(BaseLayout.*.css)を毎回サーバーに問い合わせていました。_headersを使っています。run_worker_firstは/posts/*だけなので、/_astro/*へのリクエストは Worker を通らず、Worker の変更は不要です。/link-card-images/*は対象外にしました。cacheImage()はダウンロードした画像の内容ではなく取得元 URL をハッシュ化しているため、取得元の画像が変わってもファイル名が変わらず、古い画像が残るおそれがあります。tests/worker/asset-cache.test.ts:immutableの対象が/_astro/*以外に広がらないことを確認するテストを追加しました。docs/asset-caching.md: 対象範囲と、対象外にした理由を記載しました。計測結果
pnpm run build:ciでビルドしたdistをwrangler devで配信し、Playwright で同じブラウザコンテキストから/posts/nespresso-mold/を 2 回開きました。2 回目の表示を 5 回計測した中央値です(解析タグは除外)。CSS とアバター画像は、2 回目以降はサーバーに問い合わせずブラウザのキャッシュから読み込まれます。localhost では往復の遅延がほぼないため、時間の差は誤差の範囲です。本番では、記事を移動するたびに CSS の再検証 1 往復が減る見込みですが、デプロイ前のため本番の値は計測していません。
再現方法
コスト・注意点
/_astro/*に、ハッシュを含まない固定名のファイルを置くと、ブラウザに最長 1 年間古いものが残ります。Astro が生成するファイルだけが置かれる前提です。テスト
pnpm run lint: エラー 0pnpm run test:worker: 74 件成功pnpm run test:e2e --project=chromium: 70 件成功、2 件スキップImplemented in session Speed up blog page loads at sur33.com
Review with Devin · Open in Devin Desktop