The script tag has a very uncommon async attribute, which was first created by Firefox and then supported by chrome and Safari, but unfortunately IE does not support this attribute.
For introduction to async, see here: http://www.w3.org/TR/html5/scripting-1.html#attr-script-async
We can understand the async attributes as follows:
When the async attribute of a script is set to true, the execution sequence of the script is asynchronous. That is, it is not executed in the order of mounting to the Dom. If it is false, it is executed in the order of mounting.
If the script tag is directly encoded in HTML, The async attribute recognized by the handler is false. If the script is obtained from document. createelement ("script"), The async attribute is true.
IE, Safari, and opera are completely irrelevant. If you dynamically create a script tag, opera will execute the script in the order it is mounted to the Dom, however, the asynchronous execution of IE and Safari is not powerful at this time.
There is a problem here. We have a need to dynamically load JavaScript, and it is possible to dynamically load one or more JavaScript scripts at any time, in addition, this load must be cross-origin. Xhr injection (loading JavaScript code dynamically) cannot be considered. Then how can we perform sequential download and execution?
We can try this method. First, we use a script tag of type = "text/SEED" to download all the scripts, you can also set it to whatever text/someelse you want to set. Of course, JavaScript cannot be written. After all the scripts are downloaded, the script tag is re-generated in sequence and mounted to the DOM tree.
This is equivalent to using the browser cache to pre-load the file and then execute it one by one. However, this solution has no theoretical basis, because I don't know how the browser uses the cache. However, all the tested browsers have achieved the expected results.