Allow registration of scripts as "async" or "defer" via CClientScript #1724

Closed
fiesh opened this Issue Nov 19, 2012 · 6 comments

5 participants

@fiesh
fiesh commented Nov 19, 2012

For performance reasons, it is very important to have script tags have one of the following two forms (preferably the first I think, but if this is added then the second should also be made accessible):

<script type="text/javascript" async="async" src="something.js"></script>
<script type="text/javascript" defer="defer" src="something.js"></script>

Alas CHtml::scriptFile() doesn't have any such option, and consecutively CClientScript can't do it. I think this would be a very helpful add on.

@fiesh fiesh pushed a commit to fiesh/yii that referenced this issue Feb 9, 2013
fiesh Allow registering scripts as async, [closes #1724] 62e8fd7
@klimov-paul
Member

Both "async" and "defer" should be available.

@klimov-paul
Member

Do not forget about "onload" option for the "script" tag. It also may be useful.

@klimov-paul
Member

Perhaps this feature can satisfy #198

@fiesh
fiesh commented Mar 5, 2013

For #198, I think require.js would be the correct solution. In fact implementing require.js into Yii would be the best solution, that's what I did for myself, and then having the ability to use CClientScript::registerScript() with a require parameter that wraps the whole script in a require() block. But I read somewhere on the forum that require.js was not wanted in Yii, so I didn't pursue this any further.

This is also why I consider this issue here kind of unimportant now, just registering async only very rarely is what you want, require.js is the correct solution. But Yii doesn't want it I guess.

@klimov-paul klimov-paul added a commit to klimov-paul/yii that referenced this issue Mar 6, 2013
@klimov-paul klimov-paul Issue #1724 has been added to CHANGELOG 8616cdd
@resurtm
Contributor
resurtm commented Mar 9, 2013

Voting for #2172 to be merged instead of #2093.

Another real use case: http://vk.com/pages.php?act=share
Embedding code requires charset attribute to be set:

<!-- Put this script tag to the <head> of your page -->
<script type="text/javascript" src="http://vk.com/js/api/share.js?11" charset="windows-1251"></script>
@samdark samdark was assigned Mar 9, 2013
@samdark samdark closed this Mar 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment