[英]Yii framework add defer in script tag
How to add defer in script tag? 如何在脚本标签中添加延迟? I using this
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js');
我使用这个
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js');
And I try to change to Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js', CClientScript::POS_HEAD,array('defer'=>'defer'));
我尝试更改为
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js', CClientScript::POS_HEAD,array('defer'=>'defer'));
or Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js', CClientScript::POS_HEAD,array('id'=>'defer'));
或
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js', CClientScript::POS_HEAD,array('id'=>'defer'));
is not work. 是行不通的。 I didn't know how to do.
我不知道该怎么办。 Please help.
请帮忙。
I found this way: 我发现是这样的:
Check the function registerScriptFile() in CClientScript.php , if the param htmlOptions does not exist, replace 2 files bellow in your source from https://github.com/yiisoft/yii 检查CClientScript.php中的函数registerScriptFile(),如果htmlOptions参数不存在,请从https://github.com/yiisoft/yii替换源代码中的2个文件
'defer'=>1
of function renderAttributes()
in file CHtml.php renderAttributes()
注释行'defer'=>1
You can provide the option such as 您可以提供以下选项
$this->registerJsFile('https://apis.google.com/js/platform.js?onload=renderButton',['position' => View::POS_END, 'async'=>true, 'defer'=>true]);
To add interanl js 添加内部js
$this->registerJsFile(Yii::$app->view->theme->baseUrl .'/your_js_path',['position' => View::POS_END, 'async'=>true, 'defer'=>true]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.