<SCRIPT src = "../file. js" async = "async"> </SCRIPT>
File. js ----
Only alert ("Hello, world ");
The async attribute is only applicable to external scripts (only when the src attribute is used ).
There are multiple ways to execute external scripts:
- If async = "async": the script is executed asynchronously relative to the rest of the page (when the page continues to be parsed, the script will be executed)
- If async is not used and defer = "Defer": the script will be executed when parsing is completed on the page.
- If neither async nor defer is used: read and execute the script immediately before the browser continues parsing the page
Code execution in IE8 does not reflect the asynchronous function. The execution sequence is:
(1) Hello, world
(2) Close "Hello, world" and render the BOM Interface
Execute the same code in chorme to reflect the asynchronous feature, that is, the pop-up Hello, world and the rendering browser simultaneously
After the OK button is closed, the execution page is as follows:
The execution result in chorme is as follows:
<SCRIPT> defer and async