js & css cache, minify

This commit is contained in:
Ulf Gebhardt 2016-01-18 07:22:28 +01:00
parent 5bc1c6cd11
commit 8930981821
7 changed files with 65 additions and 6 deletions

View File

@ -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);}

26
cache/cache_css.php vendored Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace SYSTEM\CACHE;
class cache_css {
const CACHE_CSS = 1;
public static function put($ident,$data){
return \SYSTEM\CACHE\cache::put(self::CACHE_CSS, $ident, 'css',$data);}
public static function get($ident,$header = false){
return \SYSTEM\CACHE\cache::get(self::CACHE_CSS, $ident,$header);}
public static function ident($files){
$ident = '';
foreach($files as $f){
$unique = time() % 60*15;
$ident .= $f.';'.$unique.'|';}
return sha1($ident);
}
public static function url($files){
$ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_css::get($ident)){
\LIB\lib_minify::php();
$minifier = new \MatthiasMullie\Minify\CSS();
foreach($files as $f){
$minifier->add($f);}
\SYSTEM\CACHE\cache_css::put($ident, $minifier->minify());}
return './api.php?call=cache&id='.self::CACHE_CSS.'&ident='.$ident;
}
}

26
cache/cache_js.php vendored Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace SYSTEM\CACHE;
class cache_js {
const CACHE_JS = 1;
public static function put($ident,$data){
return \SYSTEM\CACHE\cache::put(self::CACHE_JS, $ident, 'js',$data);}
public static function get($ident,$header = false){
return \SYSTEM\CACHE\cache::get(self::CACHE_JS, $ident,$header);}
public static function ident($files){
$ident = '';
foreach($files as $f){
$unique = time() % 60*15;
$ident .= $f.';'.$unique.'|';}
return sha1($ident);
}
public static function url($files){
$ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_js::get($ident)){
\LIB\lib_minify::php();
$minifier = new \MatthiasMullie\Minify\JS();
foreach($files as $f){
$minifier->add($f);}
\SYSTEM\CACHE\cache_js::put($ident, $minifier->minify());}
return './api.php?call=cache&id='.self::CACHE_JS.'&ident='.$ident;
}
}

View File

@ -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);
}
}

View File

@ -13,3 +13,4 @@ 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';
require_once dirname(__FILE__).'/minify/autoload.inc';

View File

@ -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<count($result);$i++){

View File

@ -34,3 +34,4 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (90, 0, 4, -1, NULL, '_lang', 'LANG');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (91, 0, 4, -1, NULL, '_result', 'RESULT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (92, 0, 4, -1, NULL, '_escaped_fragment_', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (93, 0, 4, -1, NULL, '_', 'STRING');