diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index 2b46b5d35..9ca6d9af7 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -90,6 +90,9 @@ class StyleSheet */ protected $app; + /** @var string[] Pre-compiled CSS files */ + protected $cssFiles = []; + /** * Less compiler * @@ -123,7 +126,11 @@ class StyleSheet { foreach ($this->app->getLibraries() as $library) { foreach ($library->getCssAssets() as $lessFile) { - $this->lessCompiler->addLessFile($lessFile); + if (substr($lessFile, -4) === '.css') { + $this->cssFiles[] = $lessFile; + } else { + $this->lessCompiler->addLessFile($lessFile); + } } } @@ -186,6 +193,16 @@ class StyleSheet $this->lessCompiler->setThemeMode($this->pubPath . '/css/modes/'. $mode . '.less'); } + /** + * Get all collected files + * + * @return string[] + */ + protected function getFiles(): array + { + return array_merge($this->cssFiles, $this->lessCompiler->getLessFiles()); + } + /** * Get the stylesheet for PDF export * @@ -213,7 +230,13 @@ class StyleSheet if ($minified) { $this->lessCompiler->compress(); } - return $this->lessCompiler->render(); + + $css = ''; + foreach ($this->cssFiles as $cssFile) { + $css .= file_get_contents($cssFile); + } + + return $css . $this->lessCompiler->render(); } /** @@ -233,14 +256,15 @@ class StyleSheet $noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache'; - if (! $noCache && FileCache::etagMatchesFiles($styleSheet->lessCompiler->getLessFiles())) { + $collectedFiles = $styleSheet->getFiles(); + if (! $noCache && FileCache::etagMatchesFiles($collectedFiles)) { $response ->setHttpResponseCode(304) ->sendHeaders(); return; } - $etag = FileCache::etagForFiles($styleSheet->lessCompiler->getLessFiles()); + $etag = FileCache::etagForFiles($collectedFiles); $response->setHeader('ETag', $etag, true) ->setHeader('Content-Type', 'text/css', true);