diff --git a/.htaccess b/.htaccess index 4986f7d380f..ecb7046aab2 100644 --- a/.htaccess +++ b/.htaccess @@ -47,6 +47,10 @@ Header set Cache-Control "max-age=15778463" + + Header set Cache-Control "max-age=15778463, immutable" + + # Let browsers cache WOFF files for a week Header set Cache-Control "max-age=604800" diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php index b9df2e95622..9558c695692 100644 --- a/apps/theming/lib/Controller/IconController.php +++ b/apps/theming/lib/Controller/IconController.php @@ -97,7 +97,7 @@ class IconController extends Controller { } if ($iconFile !== false) { $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); - $response->cacheFor(86400); + $response->cacheFor(86400, false, true); return $response; } diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php index 821291427d9..5205d3bce0e 100644 --- a/apps/theming/tests/Controller/IconControllerTest.php +++ b/apps/theming/tests/Controller/IconControllerTest.php @@ -102,7 +102,7 @@ class IconControllerTest extends TestCase { ->with('icon-core-filetypes_folder.svg') ->willReturn($file); $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); - $expected->cacheFor(86400); + $expected->cacheFor(86400, false, true); $this->assertEquals($expected, $this->iconController->getThemedIcon('core', 'filetypes/folder.svg')); } diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 1224ea39877..30b0a45c13d 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -167,8 +167,10 @@ class PreviewController extends Controller { try { $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); - $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); - $response->cacheFor(3600 * 24); + $response = new FileDisplayResponse($f, Http::STATUS_OK, [ + 'Content-Type' => $f->getMimeType(), + ]); + $response->cacheFor(3600 * 24, false, true); return $response; } catch (NotFoundException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index ee10d483b25..1a84affbe57 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -103,10 +103,10 @@ class Response { * @return $this * @since 6.0.0 - return value was added in 7.0.0 */ - public function cacheFor(int $cacheSeconds, bool $public = false) { + public function cacheFor(int $cacheSeconds, bool $public = false, bool $immutable = false) { if ($cacheSeconds > 0) { $pragma = $public ? 'public' : 'private'; - $this->addHeader('Cache-Control', $pragma . ', max-age=' . $cacheSeconds . ', must-revalidate'); + $this->addHeader('Cache-Control', sprintf('%s, max-age=%s, %s', $pragma, $cacheSeconds, ($immutable ? 'immutable' : 'must-revalidate'))); $this->addHeader('Pragma', $pragma); // Set expires header