1. There should be as few <script> tags as possible (although having more than one will not cause the program to report an error), because each <script> tag will block page rendering when it is initially downloaded <br>2. < Try not to place the script> tag at the top of the page, but try to place it at the bottom of the <body>, because when each <script> is executed, the corresponding js file will be downloaded, and the browser will wait for all js/css to be downloaded. The page will be displayed only after completion <br> 3. When multiple js files need to be imported, usually we write two <script src="..." />, which actually supports one-time import. Multiple, for example: <script src="file1.js&file2.js" /> <br>4. There is an attribute in the <script> tag: defer, which indicates that the script contained in this element will not be modified. DOM, so the code can safely delay execution, but this attribute is only supported by IE4 and Firefox3.5 browsers. I hope you pay attention when using it. If it is used by other browsers, it will be ignored directly. Usage example: </p>
<p><script type="text/javascript" src="file1.js" defer /> </p>
<p>, test verification defer attribute example: </p>
<p></p>
<div class="codetitle">
<span><a style="CURSOR: pointer" data="23130" class="copybut" id="copybut23130" onclick="doCopy('code23130')"><u>Copy code</u></a></span> The code is as follows:</div>
<div class="codebody" id="code23130">
<br><script defer>alert("defer"); </script>
<script>alert("script");</script>
<script> <br>window.onload = function() { <br>alert("load" ); <br>}; <br></script>
Under our normal understanding, the order of execution of this code should be: defer, script, load, but if the order on a browser that supports defer is: script, defer, load, it should be noted here: defer does not follow Executed after the script, but called before the onload event is handled.
Time is limited, so let’s record so much today