When defer present, it indicates that the script is being executed when the page has finished parsing. It does not include async scripts.
If I have the following situation in which all scripts will record the date when it was executed:
<head> <link rel="stylesheet" href="style.css"> <script src="script.js" async></script> <script src="script2.js" async></script> <script src="script3.js" defer></script> </head> <body> <script> console.log("Body script executed at : " + new Date()); </script> </body>
I can get this output:
Body script executed at : Tue Feb 17 2015 00:05:08 GMT-0300 script2.js:2 Script 2 executed at :Tue Feb 17 2015 00:05:08 GMT-0300 script.js:2 Script 1 executed at:Tue Feb 17 2015 00:05:08 GMT-0300 script3.js:2 Script 3 executed at :Tue Feb 17 2015 00:05:08 GMT-0300
script3.js (defer) will wait for ' <body> ', but not for script1.js (async) , script2.js(async) .
Here is the plunker
source share