diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php index 35fde6a19..c209672aa 100644 --- a/library/Icinga/Web/JavaScript.php +++ b/library/Icinga/Web/JavaScript.php @@ -25,15 +25,11 @@ class JavaScript ); protected static $vendorFiles = array( - 'js/vendor/jquery-2.1.0.min.js', - 'js/vendor/jquery.sparkline.min.js' + // 'js/vendor/jquery-1.11.0', + 'js/vendor/jquery-2.1.0', + 'js/vendor/jquery.sparkline' ); - public static function listFiles() - { - return array_merge(self::$vendorFiles, self::$jsFiles, self::listModuleFiles()); - } - public static function listModuleFiles() { $list = array(); @@ -46,18 +42,29 @@ class JavaScript } public static function sendMinified() + { + return self::send(true); + } + + public static function send($minified = false) { header('Content-Type: application/javascript'); $basedir = Icinga::app()->getBootstrapDirecory(); $js = $out = ''; + $min = $minified ? '.min' : ''; // TODO: Cache header - header('Content-Type: text/css'); + header('Content-Type: application/javascript'); + $cacheFile = '/tmp/cache_icinga' . $min . '.js'; + if (file_exists($cacheFile)) { + readfile($cacheFile); + exit; + } // We do not minify vendor files foreach (self::$vendorFiles as $file) { - $out .= file_get_contents($basedir . '/' . $file); + $out .= file_get_contents($basedir . '/' . $file . $min . '.js'); } foreach (self::$jsFiles as $file) { @@ -69,8 +76,13 @@ class JavaScript $js .= file_get_contents($module->getJsFilename()); } } - - $out .= Minifier::minify($js, array('flaggedComments' => false)); + if ($minified) { + $out .= Minifier::minify($js, array('flaggedComments' => false)); + } else { + $out .= $js; + } + // Not yet, this is for tests only. Waiting for Icinga\Web\Cache + // file_put_contents($cacheFile, $out); echo $out; } } diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index 365eedaf1..fab961768 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -34,14 +34,35 @@ class StyleSheet return $less->compile(); } - public static function send() + public static function sendMinified() + { + self::send(true); + } + + public static function send($minified = false) { header('Content-Type: text/css'); + + $min = $minified ? '.min' : ''; + $cacheFile = '/tmp/cache_icinga' . $min . '.css'; + if (file_exists($cacheFile)) { + readfile($cacheFile); + exit; + } + $less = new LessCompiler(); $basedir = Icinga::app()->getBootstrapDirecory(); foreach (self::$lessFiles as $file) { $less->addFile($basedir . '/' . $file); } - echo $less->addLoadedModules()->compile(); + $less->addLoadedModules(); + if ($minified) { + $less->compress(); + } + $out = $less->compile(); + // Not yet, this is for tests only. Waiting for Icinga\Web\Cache + // file_put_contents($cacheFile, $out); + echo $out; + } }