Home > Web Front-end > JS Tutorial > body text

A brief discussion on page loading js and performance analysis methods_javascript skills

WBOY
Release: 2016-05-16 16:28:07
Original
1359 people have browsed it

1. Loading

First load the reference js file of the static page, and then check whether the reference file contains the onload function. For example, main.js contains the onload function. Find whether there are references to other js files in main.js. Load the reference js first. Files, the loading order of the referenced files is consistent with the order of main.js.
After loading is completed, the onload function starts to be executed. Since the js execution sequence is sequential, in order to improve the page response speed, the general approach is to only draw the page in onload, and some event binding functions, ajax methods, etc. can be written later.

2. Response speed analysis

1. Use tools for analysis

The developer tools of major browsers (Firefox is my favorite) can easily check the loading and execution time of each js file, html file, css file and image.

2. Hard coding analysis

In the first step, we can basically locate the bottleneck js file. In the bottleneck js, we can use console.time('test') and console.Endtime('test') statements to pinch js functions and code blocks. Get the execution time. However, the console statement is only valid when executed in non-IE browsers, and an error will be reported under IE. If you prefer to use IE, use timestamps. When pinching, the more convenient method is to pinch the entire js file directly, and then use Firefox browser. Press F12 to see the time consumption of all functions and code blocks in the target js in the console, and you can locate the bottleneck code. at.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!