View Single Post
  #1 (permalink)  
Old October 4th, 2016, 10:34 PM
brsastre brsastre is offline
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2016
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deferred attribute

From the book:

"HTML 4.01 defines an attribute named defer for the <script> element. The purpose of defer is to indicate that a script won’t be changing the structure of the page as it executes. As such, the script can be run safely after the entire page has been parsed. Setting the defer attribute on a <script>"

"Even though the <script> elements in this example are included in the document <head>, they will not be executed until after the browser has received the closing </html> tag. The HTML5 specification indicates that scripts will be executed in the order in which they appear, so the first deferred script executes before the second deferred script, and both will execute before the
DOMContentLoaded event
".


From Mozilla Developer Center

"The DOMContentLoaded event is fired when the document has been completely loaded and parsed"

So...

1. The script can be run safely after the entire page has been parsed.
2. ...and both will execute [B]before the DOMContentLoaded event
3. The DOMContentLoaded event is fired when the document has been completely loaded and parsed.

Isn't this a contradiction? 1 and 2 ?

Defer executes the script after (1) or before (2) the document has been parsed (3) ?

Thanks!
Reply With Quote