Async script loading is what i'm learning now. I have a question about async
attr in script tag - <script async src="...">
.
here is some info, http://www.w3schools.com/tags/att_script_async.asp and my question is about this - When present, it specifies that the script will be executed asynchronously as soon as it is available. line.
Question: If i have 2 scripts:
<script async src="url1.js"><script> // 200kb
<script async src="url2.js"><script> // 2kb
and the second script
must be executed AFTER first (it uses some Objects
or functions
from it) - will it be so after page load? will first script execute first after loading, and then - the second, or not?
From bold string above - I understand it so, that than faster the script
was loaded - the faster it will be executed, and in our example we will have errors, while first script
wasn't loaded and executed yet, but second is already trying to get it. (and when we can use async
script loading? only when our scripts are not independent of each other?)
p.s. is lazy loading script
the only way to get the correct script execution order in this case - to prevent errors?