mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 13:54:26 +02:00
Web\StyleSheet: use Cache and ETags
This commit is contained in:
parent
ff6483cec5
commit
f0d6cf994e
@ -5,6 +5,7 @@
|
|||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Web\FileCache;
|
||||||
use Icinga\Web\LessCompiler;
|
use Icinga\Web\LessCompiler;
|
||||||
|
|
||||||
class StyleSheet
|
class StyleSheet
|
||||||
@ -44,28 +45,45 @@ class StyleSheet
|
|||||||
|
|
||||||
public static function send($minified = false)
|
public static function send($minified = false)
|
||||||
{
|
{
|
||||||
|
$app = Icinga::app();
|
||||||
|
$basedir = $app->getBootstrapDirecory();
|
||||||
|
foreach (self::$lessFiles as $file) {
|
||||||
|
$lessFiles[] = $basedir . '/' . $file;
|
||||||
|
}
|
||||||
|
$files = $lessFiles;
|
||||||
|
foreach ($app->getModuleManager()->getLoadedModules() as $name => $module) {
|
||||||
|
if ($module->hasCss()) {
|
||||||
|
$files[] = $module->getCssFilename();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($etag = 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: text/css');
|
header('Content-Type: text/css');
|
||||||
|
|
||||||
$min = $minified ? '.min' : '';
|
$min = $minified ? '.min' : '';
|
||||||
$cacheFile = '/tmp/cache_icinga' . $min . '.css';
|
$cacheFile = 'icinga-' . $etag . $min . '.css';
|
||||||
if (file_exists($cacheFile)) {
|
$cache = FileCache::instance();
|
||||||
readfile($cacheFile);
|
if ($cache->has($cacheFile)) {
|
||||||
exit;
|
$cache->send($cacheFile);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$less = new LessCompiler();
|
$less = new LessCompiler();
|
||||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
foreach ($lessFiles as $file) {
|
||||||
foreach (self::$lessFiles as $file) {
|
$less->addFile($file);
|
||||||
$less->addFile($basedir . '/' . $file);
|
|
||||||
}
|
}
|
||||||
$less->addLoadedModules();
|
$less->addLoadedModules();
|
||||||
if ($minified) {
|
if ($minified) {
|
||||||
$less->compress();
|
$less->compress();
|
||||||
}
|
}
|
||||||
$out = $less->compile();
|
$out = $less->compile();
|
||||||
// Not yet, this is for tests only. Waiting for Icinga\Web\Cache
|
$cache->store($cacheFile, $out);
|
||||||
// file_put_contents($cacheFile, $out);
|
|
||||||
echo $out;
|
echo $out;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user