generate seperate css/js cache files for libs & core files
This commit is contained in:
parent
0b75b559a0
commit
e740d03101
3 changed files with 49 additions and 10 deletions
|
@ -337,18 +337,40 @@ class Page {
|
|||
$this->add_html_header("<link rel='icon' type='image/x-icon' href='$data_href/favicon.ico'>", 41);
|
||||
$this->add_html_header("<link rel='apple-touch-icon' href='$data_href/apple-touch-icon.png'>", 42);
|
||||
|
||||
//We use $config_latest to make sure cache is reset if config is ever updated.
|
||||
$config_latest = 0;
|
||||
foreach(zglob("data/config/*") as $conf) {
|
||||
$config_latest = max($config_latest, filemtime($conf));
|
||||
}
|
||||
|
||||
$css_files = array();
|
||||
/*** Generate CSS cache files ***/
|
||||
$css_lib_latest = $config_latest;
|
||||
$css_lib_files = zglob("lib/vendor/css/*.css");
|
||||
foreach($css_lib_files as $css) {
|
||||
$css_lib_latest = max($css_lib_latest, filemtime($css));
|
||||
}
|
||||
$css_lib_md5 = md5(serialize($css_lib_files));
|
||||
$css_lib_cache_file = data_path("cache/style.lib.{$theme_name}.{$css_lib_latest}.{$css_lib_md5}.css");
|
||||
if(!file_exists($css_lib_cache_file)) {
|
||||
$css_lib_data = "";
|
||||
foreach($css_lib_files as $file) {
|
||||
$file_data = file_get_contents($file);
|
||||
$pattern = '/url[\s]*\([\s]*["\']?([^"\'\)]+)["\']?[\s]*\)/';
|
||||
$replace = 'url("../../'.dirname($file).'/$1")';
|
||||
$file_data = preg_replace($pattern, $replace, $file_data);
|
||||
$css_lib_data .= $file_data . "\n";
|
||||
}
|
||||
file_put_contents($css_lib_cache_file, $css_lib_data);
|
||||
}
|
||||
$this->add_html_header("<link rel='stylesheet' href='$data_href/$css_lib_cache_file' type='text/css'>", 43);
|
||||
|
||||
$css_latest = $config_latest;
|
||||
foreach(array_merge(zglob("lib/*.css"), zglob("ext/*/style.css"), zglob("themes/$theme_name/style.css")) as $css) {
|
||||
$css_files[] = $css;
|
||||
$css_files = array_merge(zglob("lib/shimmie.css"), zglob("ext/*/style.css"), zglob("themes/$theme_name/style.css"));
|
||||
foreach($css_files as $css) {
|
||||
$css_latest = max($css_latest, filemtime($css));
|
||||
}
|
||||
$css_cache_file = data_path("cache/style.$theme_name.$css_latest.css");
|
||||
$css_md5 = md5(serialize($css_files));
|
||||
$css_cache_file = data_path("cache/style.main.{$theme_name}.{$css_latest}.{$css_md5}.css");
|
||||
if(!file_exists($css_cache_file)) {
|
||||
$css_data = "";
|
||||
foreach($css_files as $file) {
|
||||
|
@ -360,15 +382,32 @@ class Page {
|
|||
}
|
||||
file_put_contents($css_cache_file, $css_data);
|
||||
}
|
||||
$this->add_html_header("<link rel='stylesheet' href='$data_href/$css_cache_file' type='text/css'>", 43);
|
||||
$this->add_html_header("<link rel='stylesheet' href='$data_href/$css_cache_file' type='text/css'>", 44);
|
||||
|
||||
/*** Generate JS cache files ***/
|
||||
$js_lib_latest = $config_latest;
|
||||
$js_lib_files = zglob("lib/vendor/js/*.js");
|
||||
foreach($js_lib_files as $js) {
|
||||
$js_lib_latest = max($js_lib_latest, filemtime($js));
|
||||
}
|
||||
$js_lib_md5 = md5(serialize($js_lib_files));
|
||||
$js_lib_cache_file = data_path("cache/script.lib.{$theme_name}.{$js_lib_latest}.{$js_lib_md5}.js");
|
||||
if(!file_exists($js_lib_cache_file)) {
|
||||
$js_data = "";
|
||||
foreach($js_lib_files as $file) {
|
||||
$js_data .= file_get_contents($file) . "\n";
|
||||
}
|
||||
file_put_contents($js_lib_cache_file, $js_data);
|
||||
}
|
||||
$this->add_html_header("<script src='$data_href/$js_lib_cache_file' type='text/javascript'></script>", 45);
|
||||
|
||||
$js_files = array();
|
||||
$js_latest = $config_latest;
|
||||
foreach(array_merge(zglob("lib/*.js"), zglob("ext/*/script.js"), zglob("themes/$theme_name/script.js")) as $js) {
|
||||
$js_files[] = $js;
|
||||
$js_files = array_merge(zglob("lib/shimmie.js"), zglob("ext/*/script.js"), zglob("themes/$theme_name/script.js"));
|
||||
foreach($js_files as $js) {
|
||||
$js_latest = max($js_latest, filemtime($js));
|
||||
}
|
||||
$js_cache_file = data_path("cache/script.$theme_name.$js_latest.js");
|
||||
$js_md5 = md5(serialize($js_files));
|
||||
$js_cache_file = data_path("cache/script.main.{$theme_name}.{$js_latest}.{$js_md5}.js");
|
||||
if(!file_exists($js_cache_file)) {
|
||||
$js_data = "";
|
||||
foreach($js_files as $file) {
|
||||
|
@ -376,7 +415,7 @@ class Page {
|
|||
}
|
||||
file_put_contents($js_cache_file, $js_data);
|
||||
}
|
||||
$this->add_html_header("<script src='$data_href/$js_cache_file' type='text/javascript'></script>", 44);
|
||||
$this->add_html_header("<script src='$data_href/$js_cache_file' type='text/javascript'></script>", 45);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
0
lib/vendor/css/.gitkeep
vendored
Normal file
0
lib/vendor/css/.gitkeep
vendored
Normal file
0
lib/vendor/js/.gitkeep
vendored
Normal file
0
lib/vendor/js/.gitkeep
vendored
Normal file
Reference in a new issue