From b83a4b59a5eca2e828c95e20651f8bed2ac53549 Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Thu, 27 Mar 2025 16:41:22 +0100 Subject: [PATCH] perf(cache): force Firefox to send cache headers `immutable` header is only supported by Firefox and Safari. When the resource is stale, Firefox don't send `If-None-Match` and `If-Not-Modified-Since` headers. This commit force Firefox to send these headers when resources are stale. Signed-off-by: Benjamin Gaussorgues --- .htaccess | 2 +- lib/public/AppFramework/Http/Response.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.htaccess b/.htaccess index 164a630b75f9b..91b728847cf8d 100644 --- a/.htaccess +++ b/.htaccess @@ -49,7 +49,7 @@ # Add cache control for static resources - Header set Cache-Control "max-age=15778463, immutable" + Header set Cache-Control "max-age=15778463, must-revalidate, immutable" Header set Cache-Control "max-age=15778463" diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 6fc3d4b98eaeb..93e305d244517 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -89,7 +89,7 @@ public function __construct(int $status = Http::STATUS_OK, array $headers = []) public function cacheFor(int $cacheSeconds, bool $public = false, bool $immutable = false) { if ($cacheSeconds > 0) { $cacheStore = $public ? 'public' : 'private'; - $this->addHeader('Cache-Control', sprintf('%s, max-age=%s, %s', $cacheStore, $cacheSeconds, ($immutable ? 'immutable' : 'must-revalidate'))); + $this->addHeader('Cache-Control', sprintf('%s, max-age=%s, %s', $cacheStore, $cacheSeconds, ($immutable ? 'must-revalidate, immutable' : 'must-revalidate'))); // Set expires header $expires = new \DateTime();