defer 대응

This commit is contained in:
2021-09-05 03:32:57 +09:00
parent 76bd65cf53
commit 9cbead1ddc
2 changed files with 15 additions and 46 deletions
+2 -4
View File
@@ -28,11 +28,11 @@ foreach (array_keys(General::INHERITANCE_KEY) as $key) {
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=1024" />
<?= WebUtil::preloadCSS('dist_css/v_inheritPoint.css') ?>
<?= WebUtil::preloadJS('dist_js/v_inheritPoint.js') ?>
<?= WebUtil::printCSS('dist_css/common_vue.css') ?>
<?= WebUtil::printCSS('dist_css/v_inheritPoint.css') ?>
<?= WebUtil::printJS('../d_shared/common_path.js') ?>
<?= WebUtil::printJS('dist_js/vendors_vue.js') ?>
<?= WebUtil::printJS('dist_js/v_inheritPoint.js', true) ?>
<?= WebUtil::printStaticValues([
'items' => $items
]) ?>
@@ -40,8 +40,6 @@ foreach (array_keys(General::INHERITANCE_KEY) as $key) {
<body>
<div id="app"></div>
<?= WebUtil::printJS('dist_js/v_inheritPoint.js') ?>
</body>
</html>
+13 -42
View File
@@ -105,7 +105,7 @@ class WebUtil
return $decoded;
}
public static function preloadCSS(string $path){
public static function preloadAsset(string $path, string $type){
$upath = \phpUri::parse($path);
$path = $upath->join('');
if(!$upath->scheme && file_exists($upath->path)){
@@ -120,29 +120,19 @@ class WebUtil
else{
$tail = '';
}
return "<link href='{$path}{$tail}' rel='preload' as='style'>\n";
return "<link href='{$path}{$tail}' rel='preload' as='$type'>\n";
}
public static function preloadCSS(string $path){
return static::preloadAsset($path, 'style');
}
public static function preloadJS(string $path){
$upath = \phpUri::parse($path);
$path = $upath->join('');
if(!$upath->scheme && file_exists($upath->path)){
$mtime = filemtime($upath->path);
if($upath->query){
$tail = '&'.$mtime;
}
else{
$tail = '?'.$mtime;
}
}
else{
$tail = '';
}
return "<link href='{$path}{$tail}' rel='preload' as='script'>\n";
return static::preloadAsset($path, 'script');
}
public static function printJS(string $path){
//async, defer 옵션 고려
public static function printJS(string $path, bool $isDefer=false){
//async 옵션 고려?
$upath = \phpUri::parse($path);
$path = $upath->join('');
if(!$upath->scheme && file_exists($upath->path)){
@@ -157,7 +147,9 @@ class WebUtil
else{
$tail = '';
}
return "<script src='{$path}{$tail}'></script>\n";
$typeText = $isDefer?'defer':'';
return "<script {$typeText} src='{$path}{$tail}'></script>\n";
}
public static function printCSS(string $path){
@@ -188,32 +180,11 @@ class WebUtil
$lines[] = "var {$key} = ".Json::encode($value, Json::EMPTY_ARRAY_IS_DICT | ($pretty?Json::PRETTY:0));
}
$lines[] = "</script>";
$lines[] = "</script>\n";
return join("\n", $lines);
}
protected static $jsFilesList = [];
public static function pushJSFile(string $path){
static::$jsFilesList[] = $path;
}
protected static $cssFilesList = [];
public static function pushCSSFile(string $path){
static::$cssFilesList[] = $path;
}
public static function printResourceFiles(){
foreach(static::$jsFilesList as $path){
static::printJS($path);
}
foreach(static::$cssFilesList as $path){
static::printCSS($path);
}
static::$jsFilesList = [];
static::$cssFilesList = [];
}
public static function htmlPurify(?string $text): string{
if(!$text){
return '';