From 8930981821a9df20e88f9d4c289e6a79f5ef1d06 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 18 Jan 2016 07:22:28 +0100 Subject: [PATCH] js & css cache, minify --- api/api_system.php | 3 +++ cache/cache_css.php | 26 ++++++++++++++++++++++++++ cache/cache_js.php | 26 ++++++++++++++++++++++++++ cache/cache_scss.php | 3 +++ lib/autoload.inc | 3 ++- page/State.php | 7 +++---- sql/qt/mysql/data/system_api.sql | 3 ++- 7 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 cache/cache_css.php create mode 100644 cache/cache_js.php diff --git a/api/api_system.php b/api/api_system.php index 436bacd..7c70678 100644 --- a/api/api_system.php +++ b/api/api_system.php @@ -19,6 +19,9 @@ class api_system extends api_login{ \SYSTEM\locale::set($lang);} public static function static__result($result){ \SYSTEM\CONFIG\config::set(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_RESULT, $result);} + public static function static__($_){ + //cache avoidance + } public static function call_bug($message,$data){ return \SYSTEM\SAI\saimod_sys_todo::report($message,$data);} diff --git a/cache/cache_css.php b/cache/cache_css.php new file mode 100644 index 0000000..b357a86 --- /dev/null +++ b/cache/cache_css.php @@ -0,0 +1,26 @@ +add($f);} + \SYSTEM\CACHE\cache_css::put($ident, $minifier->minify());} + return './api.php?call=cache&id='.self::CACHE_CSS.'&ident='.$ident; + } +} \ No newline at end of file diff --git a/cache/cache_js.php b/cache/cache_js.php new file mode 100644 index 0000000..48f5f38 --- /dev/null +++ b/cache/cache_js.php @@ -0,0 +1,26 @@ +add($f);} + \SYSTEM\CACHE\cache_js::put($ident, $minifier->minify());} + return './api.php?call=cache&id='.self::CACHE_JS.'&ident='.$ident; + } +} \ No newline at end of file diff --git a/cache/cache_scss.php b/cache/cache_scss.php index e3b1599..3f86400 100644 --- a/cache/cache_scss.php +++ b/cache/cache_scss.php @@ -10,6 +10,9 @@ class cache_scss { return sha1($file.';'.filemtime($file)); } public static function url($file){ + if(!\SYSTEM\CACHE\cache_scss::get($file)){ + \LIB\lib_scssphp::php(); + \SYSTEM\CACHE\cache_scss::put($file, (new \Leafo\ScssPhp\Compiler())->compile(file_get_contents($file)));} return './api.php?call=cache&id='.self::CACHE_SCSS.'&ident='.self::ident($file); } } \ No newline at end of file diff --git a/lib/autoload.inc b/lib/autoload.inc index c203dd5..4999dbf 100644 --- a/lib/autoload.inc +++ b/lib/autoload.inc @@ -12,4 +12,5 @@ require_once dirname(__FILE__).'/lettering/autoload.inc'; require_once dirname(__FILE__).'/bootstrap_growl/autoload.inc'; require_once dirname(__FILE__).'/git/autoload.inc'; require_once dirname(__FILE__).'/jqbootstrapvalidation/autoload.inc'; -require_once dirname(__FILE__).'/scssphp/autoload.inc'; \ No newline at end of file +require_once dirname(__FILE__).'/scssphp/autoload.inc'; +require_once dirname(__FILE__).'/minify/autoload.inc'; \ No newline at end of file diff --git a/page/State.php b/page/State.php index 1fde7ac..7e2a465 100644 --- a/page/State.php +++ b/page/State.php @@ -31,17 +31,16 @@ class State { $row['css'] = $row['js'] = array(); if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ $row['css'] = array_merge($row['css'], \call_user_func($row['php_class'].'::css'));} - \LIB\lib_scssphp::php(); if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'scss') && \is_callable($row['php_class'].'::scss')){ $scss = \call_user_func($row['php_class'].'::scss'); foreach($scss as $s){ - if(!\SYSTEM\CACHE\cache_scss::get($s)){ - \SYSTEM\CACHE\cache_scss::put($s, (new \Leafo\ScssPhp\Compiler())->compile(file_get_contents($s)));} $row['css'][] = \SYSTEM\CACHE\cache_scss::url($s);} } + $row['css'] = count($row['css']) > 0 ? array(\SYSTEM\CACHE\cache_css::url($row['css'])) : array(); if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){ $row['js'] = array_merge($row['js'], \call_user_func($row['php_class'].'::js'));} - $row['php_class'] = ''; + //$row['js'] = count($row['css']) > 0 ? array(\SYSTEM\CACHE\cache_js::url($row['js'])) : array(); + unset($row['php_class']); $skip = false; for($i=0;$i