From beb3326631b53cbf02885a3fd8355a0f84708644 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 22 Aug 2017 09:33:28 +0200 Subject: [PATCH] StyleSheet/JavaScript: Also include Cache-Control when answering with a 304 Without Cache-Control, the browser may invalidate its cached file and we're serving the file again on the next request. refs #2917 --- library/Icinga/Web/JavaScript.php | 2 +- library/Icinga/Web/StyleSheet.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php index 76c25def8..75dd783d3 100644 --- a/library/Icinga/Web/JavaScript.php +++ b/library/Icinga/Web/JavaScript.php @@ -98,13 +98,13 @@ class JavaScript $request = Icinga::app()->getRequest(); $noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache'; + header('Cache-Control: public'); if (! $noCache && FileCache::etagMatchesFiles($files)) { header("HTTP/1.1 304 Not Modified"); return; } else { $etag = FileCache::etagForFiles($files); } - header('Cache-Control: public'); header('ETag: "' . $etag . '"'); header('Content-Type: application/javascript'); diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index 549e11c5c..63eee3647 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -182,6 +182,7 @@ class StyleSheet $request = $styleSheet->app->getRequest(); $response = $styleSheet->app->getResponse(); + $response->setHeader('Cache-Control', 'public', true); $noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache'; @@ -194,9 +195,7 @@ class StyleSheet $etag = FileCache::etagForFiles($styleSheet->lessCompiler->getLessFiles()); - $response - ->setHeader('Cache-Control', 'public', true) - ->setHeader('ETag', $etag, true) + $response->setHeader('ETag', $etag, true) ->setHeader('Content-Type', 'text/css', true); $cacheFile = 'icinga-' . $etag . ($minified ? '.min' : '') . '.css';