<script async > vs document.getElementsByTagName('script')[0].insertBefore 等等?
<script async > vs document.getElementsByTagName('script')[0].insertBefore etc.?
在
之间有什么material区别吗?
<script type="text/javascript" src="/script.js" async></script>
和
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'script.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x)
;})();
?
我只能引用MDN:
In older browsers that don't support the async
attribute, parser-inserted scripts block the parser; script-inserted scripts execute asynchronously in IE and WebKit, but synchronously in Opera and pre-4.0 Firefox.
所以换句话说,第二个仍然会在旧的 IE 和 WebKit 浏览器中异步评估脚本。
在
之间有什么material区别吗?<script type="text/javascript" src="/script.js" async></script>
和
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'script.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x)
;})();
?
我只能引用MDN:
In older browsers that don't support the
async
attribute, parser-inserted scripts block the parser; script-inserted scripts execute asynchronously in IE and WebKit, but synchronously in Opera and pre-4.0 Firefox.
所以换句话说,第二个仍然会在旧的 IE 和 WebKit 浏览器中异步评估脚本。