I recently read a book titled "high-performance javaScript" and found that many minor details exist in my javaScript writing. Although these problems do not cause program running errors, they may slow the interface loading, the user experience is poor, so let's take a closer look at the points that should be noted. 1. The fewer the script tags, the better. (although there are multiple tags, the program will not report errors ), because the page rendering is blocked during initial download of each script tag.
2. Do not place the script tag on the top of the page as much as possible.Because each script downloads the corresponding js file during execution, the browser will display the page only after all js/css downloads are complete.
3. When multiple js files need to be imported, we usually write two In fact, multiple data types can be imported at a time. For example:
4. The script tag has a property: defer, which indicates that the script contained in this element will not modify the DOM, so the code can be safely delayed, however, this attribute is only supported by IE4 + and Firefox3.5 + browsers. I hope you will note that other browsers will be ignored directly. Example:
, Test and verify the defer attribute example:
The Code is as follows: