Web optimization: The Reflow optimization theory of browsers

Source: Internet
Author: User
Tags border color html page interface

Web pages run in a variety of browsers, browser loading, rendering the speed of the page directly affect the user experience. Unfortunately, the least efficient IE browser still occupies the majority of the market share, which has seriously restricted the development of the Internet (sigh: "Mosaic and ie--hinder the development of human civilization stumbling block!" )。

Simply put, page rendering is the process that browsers display HTML code in the browser window based on the rules defined by CSS. Let's get a general idea of how browsers work:

  1. The user enters the URL (assuming it is an HTML page and is the first visit), the browser sends a request to the server, and the server returns the HTML file;
  2. The browser starts loading the HTML code and finds that there is a <link> tag inside the
  3. The browser also issued a CSS file request, the server returned to this CSS file;
  4. The browser continues to load the HTML <body> part of the code, and the CSS file has been handed, you can start rendering the page;
  5. The browser finds a tag in the code that references a picture and makes a request to the server. At this point the browser will not wait until the picture is downloaded, but continue to render the following code;
  6. The server returns the picture file, because the picture occupies a certain area, affected the layout of the following paragraphs, so the browser needs to go back to render this part of the code;
  7. The browser finds a <script> tag that contains a line of JavaScript code and runs it quickly;
  8. The JavaScript script executes this statement, which commands the browser to hide a <div> (style.display= "None") in the code. Cup, Ah, suddenly less such an element, the browser has to recreate this part of the code;
  9. Finally waiting for the arrival of
  10. Wait, not finished, the user click on the interface of the "Skin" button, JavaScript let the browser change the <link> label CSS Path;
  11. The browser has assembled all the <div><span><ul><li> in this room, "Everyone pack up, we have to start again ...", the browser to the server request a new CSS file, to render the page again.

Browsers are running back and forth every day, knowing that different people are writing HTML and CSS code that is so uneven that they might run and die one day. Fortunately this world still has such a group of people--page reconfiguration engineer, usually quite inconspicuous, also help the visual designers to correct the picture and change the word, in fact secretly still did a lot of practical things.

Speaking of pages, why is it slow? That's because the browser takes time and effort to render, especially when it finds that a certain part of the change has affected the layout and needs to be reflow back, which insiders call the retreat process.

Reflow is almost inevitable. Now some of the popular effects on the interface, such as the collapse of the tree directory, expansion (essentially the display and hidden elements), and so on, will cause the browser's reflow. Mouse slide over, click ... As long as these behaviors cause some elements on the page of the placeholder area, positioning, margin and other attributes of the changes, will cause it inside, around or even the entire page of the rendering. Usually we can't predict which part of the code the browser will reflow, they all affect each other.

The reflow problem can be optimized and we can minimize unnecessary reflow. For example, in the beginning of the example of the picture loading problem, which is actually a can be avoided reflow--to the picture set width and height can be. So the browser will know the size of the picture, in the picture before loading set aside the position.

In addition, there is a term that looks similar to reflow: Repaint, Chinese is called redrawing. If you just change the background color of an element, text color, border color, and so on that do not affect the surrounding or internal layout of the property, will only cause the browser repaint. Repaint speed is significantly faster than reflow (under IE need to change the argument, reflow more slowly than repaint). The next will be through a series of experiments in Firefox, IE and other browsers under the Reflow optimization.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.