Html 4.0 defines the defer attribute for the <script> tag, which is used when the table name script executes without affecting the construction of the Page. That is, the script is deferred until the entire page has been parsed, so setting the Defer property in the <script> element is equivalent to telling the browser to download it immediately, but defer execution. But there is a special case, see the following code:
<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head> <Metahttp-equiv= "content-type"content= "text/html; charset=utf-8"/> <title></title> <Scriptsrc= "aaa.js"defer= "defer"></Script> <Scriptsrc= "bbb.js"defer= "defer"></Script></Head><Body><DivID= "div"></Div></Body></HTML>
The code above has two external scripts, and they are all set to lazy loading, and the HTML5 specification requires that the script be executed in the order in which they appear, so the first delay script executes before the second delay script, but this is not the case, the deferred script does not necessarily follow the order. So it's best to include only one delay script!
Asynchronous script:
Like defer, async works only with external scripts and tells the browser to download files immediately, and scripts marked as Async are not guaranteed to be executed in the order in which they are specified. The following code:
<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head> <Metahttp-equiv= "content-type"content= "text/html; charset=utf-8"/> <title></title> <Scriptsrc= "aaa.js"Async></Script> <Scriptsrc= "bbb.js"Async></Script></Head><Body><DivID= "div"></Div></Body></HTML>
The two external script files in the above code are set to be loaded asynchronously, but the second one may be executed before the first script File. therefore, It is important to make sure that the two are not used.
JavaScript value delay script and asynchronous script