admin管理员组文章数量:1430468
I am trying to defer
my script execution because it is not important that it executes before the page is rendered. However, it is not working as I understand it.
According to this article (and others like it), if I use defer
then the execution order is preserved. However, when using highlight.js I am seeing a different behaviour. My script files look like so:-
<script defer type="text/javascript" src="//cdnjs.cloudflare/ajax/libs/highlight.js/8.7/highlight.min.js"></script>
<script defer type="text/javascript">hljs.initHighlightingOnLoad();</script>
Now as I understand it they should execute in order which is unlike the behaviour of async
. However, I get the following error in Chrome (version 44.0.2403.157).
If I remove the defer
attributes it works as expected. What am I not understanding correctly?
I am trying to defer
my script execution because it is not important that it executes before the page is rendered. However, it is not working as I understand it.
According to this article (and others like it), if I use defer
then the execution order is preserved. However, when using highlight.js I am seeing a different behaviour. My script files look like so:-
<script defer type="text/javascript" src="//cdnjs.cloudflare./ajax/libs/highlight.js/8.7/highlight.min.js"></script>
<script defer type="text/javascript">hljs.initHighlightingOnLoad();</script>
Now as I understand it they should execute in order which is unlike the behaviour of async
. However, I get the following error in Chrome (version 44.0.2403.157).
If I remove the defer
attributes it works as expected. What am I not understanding correctly?
-
1
wouldnt this only work if
hljs.initHighlightingOnLoad()
was also in an external file (and the loading of that file was "defer'd")? – atmd Commented Aug 26, 2015 at 11:43
1 Answer
Reset to default 6The defer attribute has been browser specific http://caniuse./#feat=script-defer (thanks to atmd)
The defer and async attributes must not be specified if the src attribute is not present.
Check your second case.
本文标签: javascriptltscript defergt not working as expectedStack Overflow
版权声明:本文标题:javascript - <script defer> not working as expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745507416a2661309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论