最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why can you only use defer when src is specified? - Stack Overflow

programmeradmin0浏览0评论

When validating code that uses the <script> tag I get the following warning on validator.w3

Element script must not have attribute defer unless attribute src is also specified.

I don't understand the need for this, could someone explain it?

When validating code that uses the <script> tag I get the following warning on validator.w3.org

Element script must not have attribute defer unless attribute src is also specified.

I don't understand the need for this, could someone explain it?

Share Improve this question edited Mar 16, 2011 at 12:47 Jakub Hampl 40.5k10 gold badges79 silver badges111 bronze badges asked Mar 16, 2011 at 12:45 TobyToby 8,79213 gold badges48 silver badges70 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

The point of defer is to say "You can keep on parsing the HTML before waiting for the script to arrive".

If the script is right there in the HTML, then you can't (since the script is in the way in the source code) and it would be pointless (since there is no external dependancy that would block parsing).

Defer attribute means asyncronous script loading (by default scripts are loaded by browser in first turn, and are executed immedialtely after loading completed).

Without src property there will be nothing to load, and nothing to defer.

发布评论

评论列表(0)

  1. 暂无评论