当前位置:网站首页>Render Optimization: repaint and reflow
Render Optimization: repaint and reflow
2022-07-25 05:05:00 【rananie】
List of articles
Rendering optimization : Repaint (Repaint) And backflow (Reflow)
Interview questions
- Have you ever understood the concept of redrawing and rearrangement ?
- transform Is the offset of this attribute rearranged or redrawn ?
- If it is transform:rotate Whether the rotation is rearranged or redrawn ?
- When will backflow be triggered ( rearrangement ) Redraw ?
- css Will asynchronous loading of files cause redrawing or reflow , Tell me your reason
What is redraw and reflow
Page layout is also called redrawing (Repaint) And backflow (Reflow)
backflow : Recalculate the... Of each box on the page according to various styles Size and location
When we are right DOM The modification of caused DOM Changes in Geometry ( For example, change the width of an element 、 High or hidden elements, etc ) when , The browser needs to recalculate the geometric properties of the elements , Then draw out the result of calculationWhen calculating the position of the box model 、 After size and other attributes , The browser draws according to the characteristics of each box
When we are right DOM The modification of led to Change of style (color or background-color), Without affecting its geometric properties , The browser doesn't have to recalculate the geometry of the element 、 Draw a new style directly for the element , This only triggers the backflow
Backflow must redraw , Repainting does not necessarily cause backflow .
Trigger timing of redrawing and reflow
backflow
- DOM Elemental Geometric properties change
- change DOM Tree structure
- Get the values of some specific properties :offsetTop、offsetLeft、 offsetWidth、offsetHeight、scrollTop、scrollLeft、scrollWidth、scrollHeight、clientTop、clientLeft、clientWidth、clientHeight.
reason : Browser optimization mechanism
Browser optimization mechanism
Because each reflux will cause additional calculation consumption , So most browsers will pass Queue modification and batch execution to optimize the reflow process . The browser will The modification operation is put into the queue , Until some time has passed or the operation has reached a threshold , Before emptying the queue
When you get the operation of the layout information , The browser will empty the queue , Triggers a backflow redraw to return the correct value , So it will force the queue to refresh
Optimization plan
- Use visibility Replace display: none , Because the former only causes a redraw , The latter causes backflow
visibility And display The difference between
display:none stay DOM Delete node from tree
visibility:hidden The node is still DOM There are... On the tree , Hide in the interface , Occupy a place in the document flow
Avoid using JavaScript Make frequent changes to the style , If it must be modified , You can reduce the number of times to trigger redrawing or reflow in the following ways
- Use the class name to modify the style one by one . stay js So let's define one css class , Add a class to the specified element
- Operate special attributes for many times, such as offset attribute , Intermediate variables can be used to cache , Submit it to offset
- adopt JS Set element properties
display: none, Remove it from the page , Then follow up ( Offline operation ), Set the attribute after the operationdisplay: block - Complex animation effects , Use absolute positioning to detach it from the document stream , Avoid affecting other layers .
css3 Hardware acceleration (GPU Speed up )
principle : Skip redrawing and reflow , Go directly to the synthesis stage
Different layers don't interact with each other
Common trigger for hardware acceleration css attribute :transform、opacity etc.
JS Realization of animation :requestAnimationFrame Tell the browser —— You want to perform an animation , It also requires the browser to invoke the specified callback function before updating the animation next time
边栏推荐
- Why does the official not recommend using UUID as MySQL primary key
- Set up private CA server
- 使用getifaddrs获取本机网口IP地址
- Harbor installation
- [live review] AI customer service "changes according to the situation", and man-machine dialogue can be easier
- Summary of UPR optimization suggestions of unity
- 基于云原生的私有化 PaaS 平台交付实践
- Small case of data analysis: visualize recruitment data and view the most needed technologies in the field~
- Introduction to FileStream class of C #
- Solve the problem that uni app applet obtains routes and route parameters
猜你喜欢

Dragon Dragon community released the first Anolis OS Security Guide to escort users' business systems

【基于stm32f103的SHT30温湿度显示】

Now the operator wants to check the answer details of all user questions from Zhejiang University. Please take out the corresponding data

This low code reporting tool is needed for data analysis

Information System Project Manager --- Chapter IX examination questions of project human resource management over the years
![[globally unique ID] how to handle the ID primary key after dividing the database and table?](/img/a1/800ee868b74ce5d98956d4a0e2c075.png)
[globally unique ID] how to handle the ID primary key after dividing the database and table?

中创算力荣获「2022年科技型中小企业」认定

The third question of force deduction -- the longest substring without repeated characters

Unity LOD

Actual combat | record an attack and defense drill management
随机推荐
Seven suggestions for Server Protection
Pyg builds GCN to realize link prediction
[sht30 temperature and humidity display based on STM32F103]
Market regulation
[untitled]
Solve the problem that uni app applet obtains routes and route parameters
QT download installation tutorial
IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…
DOM在Ahooks中的处理过程
"Niuke | daily question" inverse Polish expression
Harbor installation
How to get the database creation time?
【基于stm32f103的SHT30温湿度显示】
使用getifaddrs获取本机网口IP地址
AUTOSAR from getting started to mastering 100 lectures (105) - protection mechanism of AUTOSAR timing for functional safety
Learning records [email protected] R & D effectiveness measurement indicators
Ownership in rust -- introduction of rust language Xiaobai 11
Valley p2420 let's XOR solution
Unity LOD
Implementation principle of epoll