1. Loading
First load the reference js file of the static page, and then find whether the reference file contains the onload function, such as the main.js contains the onload function, and find whether there are references to other js files in main.js, and priority is given to load the reference js file. The loading order of files in the reference is the same as that of main.js.
After loading, start executing the onload function. Since the execution order of js is executed sequentially, in order to improve the corresponding speed of the page, it is generally to only draw the page in onload, and some event binding functions, ajax methods, etc. can be delayed writing.
2. Response speed analysis
1. Use tools to analyze
The developer tools of major browsers (like Firefox the most) can easily view the loading and execution time of each js file, html file, css file and pictures.
2. Hard-coded analysis
In the first step, we can basically locate the bottleneck js file. In bottleneck js, you can use console.time('test') and console.Endtime('test') statements to get the execution time of the js function and code blocks using the console.time('test') statements. . However, the console statement is only valid in non-IE browsers, and an error will be reported under IE. If you prefer to use IE, then use timestamps. When pinching, the more convenient method is to directly pinch the entire js file, and then use Firefox browser, press F12 to see the time-consuming of all functions and code blocks in the target js in the console, and you can locate the bottleneck code place.