Reflow of Web front-end optimization (reduce reflow of pages)

Source: Internet
Author: User

1. What is Reflow?

Reflow (reflow) refers to the process by which a browser recalculates the position and geometry of elements in a document in order to re-render some or all of the documents.

Because reflux can cause the entire DOM tree to be reconstructed, it is a major killer of performance.

The following operations can cause reflux:

① changing window size

②font-size size Change

③ Add or remove style sheets

④ content changes (input text will cause)

⑤ activating CSS Pseudo-class (: hover)

⑥ Operation class attribute, new or reduced

⑦js manipulating the DOM

⑧offset Correlation Property Calculation

⑨ setting the value of a style


Reflow and repaint are some of the main reasons to slow JS, especially reflow is a performance killer, so we should try to avoid.

<style type= "Text/css" >. changestyle {width:100px; height:100px;}</style><script type= "Text/javascript" >$ (document). Ready (function () {         varEl = $ (' ID '); //1El.css (' width ', ' 100px '); El.css (' Height ', ' 100px '); //2El.css ({' width ': ' 100px; ', ' height ': ' 100px; ') }); //3El.addclass (' Changestyle '); });</script>

Recommend the third, avoid the first type of

The above several practices, I here weak weak recommendation of the third, avoid the first kind.

② Animated effect please use absolute

Because the change of the absolute element has little effect on the reflux of other elements, the elements of our animated effect still make him into a absolute.

③ Avoid using table layouts (remember that it's just the layout, we should use the table)

④ please never use CSS expressions, performance killers, especially IE

⑤ at the last change element

Because the reflux is top-down, so it is not up to the bottom, we change the information on the last side of the overall impact less.

⑥ animation when moving, to control

For example, when we drag an element, I change the x or Y coordinate of 5px to operate, which reduces the smoothness, but improves performance.

Reflow of Web front-end optimization (reduce reflow of pages)

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: 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.