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
This commit is contained in:
parent
6702ccb2a7
commit
beb3326631
|
@ -98,13 +98,13 @@ class JavaScript
|
||||||
$request = Icinga::app()->getRequest();
|
$request = Icinga::app()->getRequest();
|
||||||
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
|
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
|
||||||
|
|
||||||
|
header('Cache-Control: public');
|
||||||
if (! $noCache && FileCache::etagMatchesFiles($files)) {
|
if (! $noCache && FileCache::etagMatchesFiles($files)) {
|
||||||
header("HTTP/1.1 304 Not Modified");
|
header("HTTP/1.1 304 Not Modified");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
$etag = FileCache::etagForFiles($files);
|
$etag = FileCache::etagForFiles($files);
|
||||||
}
|
}
|
||||||
header('Cache-Control: public');
|
|
||||||
header('ETag: "' . $etag . '"');
|
header('ETag: "' . $etag . '"');
|
||||||
header('Content-Type: application/javascript');
|
header('Content-Type: application/javascript');
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,7 @@ class StyleSheet
|
||||||
|
|
||||||
$request = $styleSheet->app->getRequest();
|
$request = $styleSheet->app->getRequest();
|
||||||
$response = $styleSheet->app->getResponse();
|
$response = $styleSheet->app->getResponse();
|
||||||
|
$response->setHeader('Cache-Control', 'public', true);
|
||||||
|
|
||||||
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
|
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
|
||||||
|
|
||||||
|
@ -194,9 +195,7 @@ class StyleSheet
|
||||||
|
|
||||||
$etag = FileCache::etagForFiles($styleSheet->lessCompiler->getLessFiles());
|
$etag = FileCache::etagForFiles($styleSheet->lessCompiler->getLessFiles());
|
||||||
|
|
||||||
$response
|
$response->setHeader('ETag', $etag, true)
|
||||||
->setHeader('Cache-Control', 'public', true)
|
|
||||||
->setHeader('ETag', $etag, true)
|
|
||||||
->setHeader('Content-Type', 'text/css', true);
|
->setHeader('Content-Type', 'text/css', true);
|
||||||
|
|
||||||
$cacheFile = 'icinga-' . $etag . ($minified ? '.min' : '') . '.css';
|
$cacheFile = 'icinga-' . $etag . ($minified ? '.min' : '') . '.css';
|
||||||
|
|
Loading…
Reference in New Issue