1, <script> label should be less the better (although there are many will not cause the program to complain), because each <script> tag initial download will block page rendering
2, <script> label as far as possible do not put on the top of the page, as far as possible in the <body> below, because each <script> in the implementation of the time, will download the corresponding JS file, the browser will wait for all js/ CSS download is complete before displaying the page
3, when the need to import a number of JS files, under normal circumstances, we are writing two <script src= "..."/>, in fact, to support a one-time import of multiple, such as: <script src= "File1.js&file2.js"/ >
4, <script> tag has a property: defer, this attribute indicates that the script contained in this element will not modify the DOM, so the code can safely delay execution, but this property only ie4+ and firefox3.5+ browser support, I hope you use the time to notice, If other browsers, it will be ignored directly, using the example:
<script type= "Text/javascript" src= "file1.js" defer/>
, test the Validation defer Property Example:
Copy Code code as follows:
<script Defer>alert ("defer");</script>
<script>alert ("script");</script>
<script>
Window.onload = function () {
Alert ("Load");
};
</script>
This code should be executed in our normal comprehension order: Defer, script, load, but if the order is script, defer, and load in the browsers that support defer, it should be noted that defer is not followed by script execution, Instead, it is invoked before the OnLoad event is processed.
Time is limited, so let's record it today.