cache JS-File to reduce response-time
no message
This commit is contained in:
parent
476502a8b0
commit
3f6a2fc7fa
@ -3,7 +3,14 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php';
|
|||||||
logger();
|
logger();
|
||||||
?>
|
?>
|
||||||
<div style="margin-bottom: 100px;"></div>
|
<div style="margin-bottom: 100px;"></div>
|
||||||
<script type='text/javascript'><?=$js_minifier->minify();?></script>
|
<script type='text/javascript'><?php
|
||||||
|
$JSPath = '/tmp/' . $js_minifier->getDataHash() . '.js';
|
||||||
|
if(file_exists($JSPath)) {
|
||||||
|
echo file_get_contents($JSPath);
|
||||||
|
} else {
|
||||||
|
echo $js_minifier->minify($JSPath);
|
||||||
|
}
|
||||||
|
?></script>
|
||||||
<script>
|
<script>
|
||||||
<?php
|
<?php
|
||||||
$lang_footer = json_encode($lang['footer']);
|
$lang_footer = json_encode($lang['footer']);
|
||||||
|
@ -30,7 +30,14 @@
|
|||||||
$css_minifier->add('/web/css/site/index.css');
|
$css_minifier->add('/web/css/site/index.css');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<style><?=$css_minifier->minify();?></style>
|
<style><?php
|
||||||
|
$CSSPath = '/tmp/' . $css_minifier->getDataHash() . '.css';
|
||||||
|
if(file_exists($CSSPath)) {
|
||||||
|
echo file_get_contents($CSSPath);
|
||||||
|
} else {
|
||||||
|
echo $css_minifier->minify($CSSPath);
|
||||||
|
}
|
||||||
|
?></style>
|
||||||
<?php if (strtolower(trim($DEFAULT_THEME)) != "lumen"): ?>
|
<?php if (strtolower(trim($DEFAULT_THEME)) != "lumen"): ?>
|
||||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/<?= strtolower(trim($DEFAULT_THEME)); ?>/bootstrap.min.css">
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/<?= strtolower(trim($DEFAULT_THEME)); ?>/bootstrap.min.css">
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
18
data/web/inc/lib/CSSminifierExtended.php
Normal file
18
data/web/inc/lib/CSSminifierExtended.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use MatthiasMullie\Minify\CSS;
|
||||||
|
|
||||||
|
class CSSminifierExtended extends CSS {
|
||||||
|
|
||||||
|
public function getDataHash() {
|
||||||
|
return sha1(json_encode($this->accessProtected($this,'data')));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function accessProtected($obj, $prop) {
|
||||||
|
$reflection = new ReflectionClass($obj);
|
||||||
|
$property = $reflection->getProperty($prop);
|
||||||
|
$property->setAccessible(true);
|
||||||
|
return $property->getValue($obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
data/web/inc/lib/JSminifierExtended.php
Normal file
18
data/web/inc/lib/JSminifierExtended.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use MatthiasMullie\Minify\JS;
|
||||||
|
|
||||||
|
class JSminifierExtended extends JS {
|
||||||
|
|
||||||
|
public function getDataHash() {
|
||||||
|
return sha1(json_encode($this->accessProtected($this,'data')));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function accessProtected($obj, $prop) {
|
||||||
|
$reflection = new ReflectionClass($obj);
|
||||||
|
$property = $reflection->getProperty($prop);
|
||||||
|
$property->setAccessible(true);
|
||||||
|
return $property->getValue($obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,16 +19,20 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/vendor/autoload.php';
|
|||||||
// Load Sieve
|
// Load Sieve
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/sieve/SieveParser.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/sieve/SieveParser.php';
|
||||||
|
|
||||||
|
// minifierExtended
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/JSminifierExtended.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/CSSminifierExtended.php';
|
||||||
|
|
||||||
// Minify JS
|
// Minify JS
|
||||||
use MatthiasMullie\Minify;
|
use MatthiasMullie\Minify;
|
||||||
$js_minifier = new Minify\JS();
|
$js_minifier = new JSminifierExtended();
|
||||||
$js_dir = array_diff(scandir('/web/js/build'), array('..', '.'));
|
$js_dir = array_diff(scandir('/web/js/build'), array('..', '.'));
|
||||||
foreach ($js_dir as $js_file) {
|
foreach ($js_dir as $js_file) {
|
||||||
$js_minifier->add('/web/js/build/' . $js_file);
|
$js_minifier->add('/web/js/build/' . $js_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minify CSS
|
// Minify CSS
|
||||||
$css_minifier = new Minify\CSS();
|
$css_minifier = new CSSminifierExtended();
|
||||||
$css_dir = array_diff(scandir('/web/css/build'), array('..', '.'));
|
$css_dir = array_diff(scandir('/web/css/build'), array('..', '.'));
|
||||||
foreach ($css_dir as $css_file) {
|
foreach ($css_dir as $css_file) {
|
||||||
$css_minifier->add('/web/css/build/' . $css_file);
|
$css_minifier->add('/web/css/build/' . $css_file);
|
||||||
|
Loading…
Reference in New Issue
Block a user