Any Way To Control Javascript Async Load Order?
How do I set the load and execution order of two external async Javascript files? Given the following... // Larger file
Solution 1:
You want to use defer
if you want to preserve the execution order. What defer
does is it async downloads the script, but defers execution till html parsing is done.
<scriptsrc="framework.js"defer></script><scriptsrc="scripts.js"defer></script>
However, you may want to start creating custom bundles once the number of scripts go higher.
You can see the difference here
Solution 2:
If you need a solution for IE9 (since it does not support the defer
attribute), I have created a small loader script:
https://github.com/mudroljub/js-async-loader
It loads all your scripts asynchronously and then executes them in order.
Post a Comment for "Any Way To Control Javascript Async Load Order?"