Prevent templates from duplicating common CSS and JS scripts

This commit is contained in:
Kijin Sung 2016-01-09 21:38:37 +09:00
parent e61bc66373
commit 4e8f048c1d
2 changed files with 23 additions and 12 deletions

View file

@ -3,6 +3,11 @@
class HTMLDisplayHandler
{
/**
* Reserved scripts
*/
public static $reservedCSS = '@\bcommon/css/(?:xe|mobile)\.(?:min\.)?css$@';
public static $reservedJS = '@\bcommon/js/(?:jquery(?:-[123]\.x)?|modernizr|xe?|common|js_app|xml_handler|xml_js_filter)\.(?:min\.)?js$@';
/**
* Produce HTML compliant content given a module object.\n
@ -409,7 +414,7 @@ class HTMLDisplayHandler
private function _loadMobileJSCSS()
{
$this->_loadCommonJSCSS();
Context::loadFile(array('./common/css/mobile.css', '', '', -1000000), true);
Context::loadFile(array('./common/css/mobile.css', '', '', -1500000), true);
}
/**
@ -417,24 +422,24 @@ class HTMLDisplayHandler
*/
private function _loadCommonJSCSS()
{
Context::loadFile(array('./common/css/xe.css', '', '', -1000000), true);
Context::loadFile(array('./common/css/xe.css', '', '', -1600000), true);
$original_file_list = array('x', 'common', 'js_app', 'xml_handler', 'xml_js_filter');
if(Context::getDBInfo()->minify_scripts === 'N')
{
Context::loadFile(array('./common/js/jquery-1.x.js', 'head', 'lt IE 9', -111000), true);
Context::loadFile(array('./common/js/jquery.js', 'head', 'gte IE 9', -110000), true);
Context::loadFile(array('./common/js/modernizr.js', 'head', '', -100000), true);
Context::loadFile(array('./common/js/jquery-1.x.js', 'head', 'lt IE 9', -1730000), true);
Context::loadFile(array('./common/js/jquery.js', 'head', 'gte IE 9', -1720000), true);
Context::loadFile(array('./common/js/modernizr.js', 'head', '', -1710000), true);
foreach($original_file_list as $filename)
{
Context::loadFile(array('./common/js/' . $filename . '.js', 'head', '', -100000), true);
Context::loadFile(array('./common/js/' . $filename . '.js', 'head', '', -1700000), true);
}
}
else
{
Context::loadFile(array('./common/js/jquery-1.x.min.js', 'head', 'lt IE 9', -111000), true);
Context::loadFile(array('./common/js/jquery.min.js', 'head', 'gte IE 9', -110000), true);
Context::loadFile(array('./common/js/modernizr.min.js', 'head', '', -100000), true);
Context::loadFile(array('./common/js/jquery-1.x.min.js', 'head', 'lt IE 9', -1730000), true);
Context::loadFile(array('./common/js/jquery.min.js', 'head', 'gte IE 9', -1720000), true);
Context::loadFile(array('./common/js/modernizr.min.js', 'head', '', -1710000), true);
$concat_target_filename = 'files/cache/minify/xe.min.js';
if(file_exists(_XE_PATH_ . $concat_target_filename))

View file

@ -93,7 +93,16 @@ class FrontEndFileHandler extends Handler
{
$args = array($args);
}
if($args[3] > -1500000 && preg_match(HTMLDisplayHandler::$reservedCSS, $args[0]))
{
return;
}
if($args[3] > -1500000 && preg_match(HTMLDisplayHandler::$reservedJS, $args[0]))
{
return;
}
$file = $this->getFileInfo($args[0], $args[2], $args[1]);
$file->index = (int)$args[3];
$availableExtension = array('css' => 1, 'js' => 1);
if(!isset($availableExtension[$file->fileExtension]))
@ -101,8 +110,6 @@ class FrontEndFileHandler extends Handler
return;
}
$file->index = (int) $args[3];
if($file->fileExtension == 'css')
{
$map = &$this->cssMap;
@ -124,7 +131,6 @@ class FrontEndFileHandler extends Handler
}
}
(is_null($file->index)) ? $file->index = 0 : $file->index = $file->index;
if(!isset($mapIndex[$file->key]) || $mapIndex[$file->key] > $file->index)
{
$this->unloadFile($args[0], $args[2], $args[1]);