Why can you use deferment only when specifying src?

When checking code using the <script> , I get the following warning on validator.w3.org

The script element must not have a defer attribute if the src attribute is also specified.

I don’t understand why this is necessary, can someone explain this?

+6
javascript html
source share
2 answers

The respite point is to say: "You can continue parsing the HTML code before waiting for the script to appear."

If the script is directly in HTML, then you cannot (because the script is in a path in the source code), and that would be pointless (since there is no external dependency that would block parsing).

+11
source share

Defer attribute means asynchronous loading of the script (by default, scripts are loaded by the browser in the first place and executed immediately after the download is completed).

There is nothing to load without the src property and nothing needs to be put off.

+2
source share

All Articles