[全体・パフォーマンス] gzip圧縮・ブラウザキャッシュヘッダーを追加しました#2407
Merged
masaton0216 merged 4 commits intomasterfrom Apr 10, 2026
Merged
Conversation
Contributor
Author
Contributor
Author
Contributor
Author
Contributor
Author
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.






概要
PageSpeed Insights のモバイルスコアが 44 点(FCP 23.8s / LCP 34.7s)と低迷していたため、Apache 側で gzip 圧縮と長期ブラウザキャッシュを有効化し、転送量を大幅に削減する対応を行いました。
合わせて、長期キャッシュ化に伴いキャッシュバスティングが効いていなかった 2 ファイル(503 メンテナンス画面・マニュアル)のバスティング不備も修正しています。
変更内容
1.
public/.htaccessに gzip 圧縮・ブラウザキャッシュヘッダーを追加mod_deflateで CSS/JS/JSON/SVG/フォント等を gzip 圧縮mod_expiresで CSS/JS/画像/フォントに 1 年間のキャッシュヘッダーを付与<IfModule>で囲んでいるため、対象モジュールが無効な環境ではスキップされ、500 にはなりません転送量削減の見込み(gzip 圧縮):
2.
resources/views/errors/503.blade.phpにキャッシュバスティングを追加asset('css/app.css')(バージョン無し){{ url('/') }}{{ mix('css/app.css') }}(?id=hash自動付与)resources/views/layouts/app.blade.php:110と同じパターンを採用しており、サブディレクトリ運用にも対応します3.
resources/views/manual/common/layout_base.blade.phpにキャッシュバスティングを追加?version={{ config('version.cc_version') }}を付与tests/Manual/html_src/配下にありpublic/配下に存在しないため、filemtime()ではなく Connect-CMS のバージョン文字列を利用しています(マニュアルは Connect-CMS のバージョンアップ時に再生成される運用のため、バージョン番号と更新タイミングが一致します)既存全アセットのキャッシュバスティング状況(調査済み)
長期キャッシュ化(1年)にあたり、全アセットのバスティング状況を事前確認しています。
問題なし(既にバスティング済み)
?id=hash)?version=filemtime()?version=filemtime()?version=timestamp本 PR で修正
resources/views/errors/503.blade.phpresources/views/manual/common/layout_base.blade.php?version={cc_version}を付与レビュー完了希望日
急ぎません(軽微な改修のため)
関連Pull requests/Issues
参考
mod_deflate/mod_expires)を前提としています。Nginx 環境では別途 nginx.conf 側での設定が必要です。留意事項
画像のキャッシュバスティングについて
本 PR により、
public/配下の静的画像(PNG/JPEG/GIF/SVG/WebP)にも 1 年間のブラウザキャッシュヘッダーが付与されます。画像種別ごとの挙動は以下の通りです。/file/{id}UploadController::getFile()で PHP がCache-Control: max-age=604800(7日)を直接付与app.css内で参照される画像.htaccessの 1 年キャッシュが効くpublic/配下の固定画像.htaccessの 1 年キャッシュが効くテーマ静的画像(バスティング無し)の運用上の注意
テーマ配下の静的画像(例:
public/themes/Xxx/img/*.png)はファイル名固定でバスティング機構がありません。本 PR 適用後、これらの画像を 同じファイル名のまま差し替えると、ブラウザは最大 1 年間古い画像を表示し続けます。想定される運用ケースと影響
/file/{id})になる同名差し替えが必要になった場合の回避策
logo_v2.png)動作確認
Content-Encoding: gzipが含まれることを確認Cache-ControlまたはExpiresが含まれることを確認php artisan downでメンテナンスモードに入り、503 ページの CSS が正常に読み込まれることを確認DB変更の有無
無し
チェックリスト