Let's take a look at a waterfall chart to determine which items are responsible for a page performance problem. Chorome Bring your own developer tools
each row in the diagram represents a http request, Each request has a time line. The time it took to identify the request. Suppose you put your mouse on a timeline. Can see the following information
- domain name resolution: search dns server and resolves the domain name to ip The event that is spent on the address. Here is 0ms
- Establish connection: client through IP Address and Web server resumes the time it takes to connect, here is 562ms
- Send request: Client to Web time taken by the server to send the request
- Wait for response: server receives from http the event that a request is taken to start the client sending content. This is 391ms. This event usually contains database queries, pages converted to HTML , and other operations
- receive data: Server response content all sent to client time, here is 94 Ms
Preliminary diagnosis of site performance bottlenecks
1) First look at which request takes longer, look at the timeline information for this request, and determine if the server responds slowly or is a problem with the network.
2) If the time spent on each request is not significantly higher than the other, then look at the page is not the The total number of HTTP requests is too many. Because the browser has a limit on the number of concurrent connections to a single domain name, a batch of requests needs to be processed and sent again. If the page has 100 requests, each request takes 1s and the maximum browser concurrency limit is 10. Then it takes 100/10*1s=10s time to finish processing the request.
about the maximum number of concurrent. The standard of Http1.1 is 2. And now the mainstream browser ie, FireFox, chrome to speed up, respectively, change to 10, 6, 6 (depending on the detailed version number may vary).
Front-end performance policy
a project engineer who specializes in Web performance finds that a page is loaded from the request to loading, 80% time spent on the front.
The same is true. Take diagram one as an example. The entire page is fully loaded and costs. Server response events are only 391ms, and other events are spent getting page static files (js,css, pictures), So optimize your site from front-end performance optimization
High PerformanceHtml
- Avoid NULL connection properties
Null connection means:img,Link Scriptand theiframeElements ofsrcorhrefthe value of the property is empty (for example:src= ""). The General browser will parse the null intoBlank, and pay the sending request.
However, IE will still send the request
- Avoid deep nesting of nodes
nodes that are deeper in the hierarchy are initialized when they are built. The more memory you consume
- reduced HTML Document Size
Delete empty lines and stares that have no effect on running results
- Avoid script blocking loading
the browser resolves the general Script label, you will wait for Script after the download is complete. Only after the parsing is run, and then the HTML code can just wait. So you should put the script at the end of the document
<script src= "Example.js" ></script> </body>
High PerformanceCSS
CSScompression is not a high-end gesture, but very practical, its principle is very easy, is to put ourCSSThe useless console symbol is deleted, to reduce the character to achieve the purpose. we have this sectionCSSScript
. test{ Background-color: #ffffff; Background-image:url (a.jpg);}
After compression, it becomes like this.
. test{Background-color: #fff; Background-image:url (a.jpg)}
- pull away, split CSS , not added in all CSS
pulling Away CSS refers to the use of some common CSS in a file, rather than write each page, such as once downloaded. Other pages will be able to use the cache, reducing unnecessary repeated downloads.
Apply the extraction principle, in very many cases we make the page common The CSS writes to a file so that it can take advantage of the cache once it is loaded, but it is not suitable for all scenarios. Once I write CSS to some front-end plug-in with the CSS to write all to a page, but sometimes the page will only use a dialog, some pages just use a treeview, but the CSS has more than 10 plugins downloaded to the page, this is the problem. So although the CSS write a file can reduce the HTTP request, but like the situation is not supposed to do this, for some of the entire page will be used we can do so, we have to pull away and split the time to think about it
UseSprites, can reduceHttpNumber of requests
believe in doing The Web's classmates are aware of this advice, but why is CSS on top of the page conducive to Web optimization? This is probably the browser rendering page, when the browser downloads HTML generation Domtree from the top to the next side to render the page based on the browser default and the existing CSS generated by the render tree. When the new CSS is encountered to download and combine the existing CSS again to generate the render tree, just the rendering work is wasted, Suppose we put all the CSS on the top of the page. So there's no more rendering process.
- do not use tag name restrictions class rules
Summary:
Web performance optimization, mainly based on tool analysis to view. The remedy should be optimized in terms of main impact.
Web Performance optimization