您可以同时使用异步和推迟一个HTML脚本标记属性? [英] Can you use both the async and defer attributes on a HTML script tag?

查看:119
本文介绍了您可以同时使用异步和推迟一个HTML脚本标记属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的JavaScript code加载都推迟和异步:

I would like to load in the following JavaScript code using both defer and async:

<脚本延迟异步SRC =/ JS / somescript.js>< / SCRIPT>

由于延迟是由Internet Explorer 5.5以上支持,因为你可以在 CanIUse.com 看到,我想优雅还原到使用推迟,如果异步不可用。异步我认为是更好地利用可用时,但其之前,不支持的Internet Explorer 10。

Since defer is supported by Internet Explorer 5.5+, as you can see at CanIUse.com, I would like to gracefully fallback to using defer if async is not available. Async I think is better to use when it is available but its not supported until Internet Explorer 10.

因此​​,我的问题是,在上述code有效的HTML?如果没有,是有可能创造使用的正常回落的JavaScript这种情况下使用推迟对脚本时异步不可用?

My question is therefore is the above code valid HTML? If not, is it possible to create this situation using JavaScript of gracefully falling back to using defer on a script when async is not available?

推荐答案

从规格:的 https://www.w3.org/TR/html5/scripting-1.html#attr-script-async

defer属性可能即使指定异步属性来指定,导致传统的Web浏览器仅支持延迟(而不是异步)回落到了延迟的行为,而不是同步阻塞行为是默认的。

The defer attribute may be specified even if the async attribute is specified, to cause legacy Web browsers that only support defer (and not async) to fall back to the defer behavior instead of the synchronous blocking behavior that is the default.

这篇关于您可以同时使用异步和推迟一个HTML脚本标记属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆