HTML5 script tags, delay expectations on any previous async scripts

HTML5 tag download directives look pretty cool

Is it possible to load a bunch of scripts asynchronously, but wait for one wait for the script based on asynchronous terminations.

<script src="//some.cdn/jquery.js" async></script> <script src="//some.cdn/underscore.js" async></script> <script src="/my-app-which-uses-_-and-jquery.js" defer></script> 

Is it possible to execute my application script after my libraries, or will it only run according to other deferral scripts?

+6
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/982580/


All Articles