Web interview frequently asked questions: the principles and differences between reflow and repaint

Web interview frequently asked questions: the principles and differences between reflow and repaint

The browser's rendering mechanism

1. Browsers use two engines to process pages, and different browsers use different rendering engines

Rendering Engine:

Chrom and Safari use "WebKit",

Firefor uses "Geoko"

js engine

2. The browser will parse HTML into DOM tree, parse css into CSSOM (CSS Object Model);

3. Then the DOM tree and CSSOM will be combined to produce render tree(render tree);

4. After the render tree is completed, the browser will layout according to the render tree. After the layout is completed, a "box model" will be output, which will accurately capture the position and size of each node in the view, and all measurements will be converted into physical pixel values ​​on the screen; (This step will cause回流(reflow) )

5. After the layout is completed, the browser will immediately issue a paint stup event to convert the render tree into screen pixels; (this step will cause重繪(repaint) )

6.After the above steps, the page will be displayed on the screen.

insert image description here

Note that reflow will inevitably cause redrawing, but redrawing does not necessarily cause reflow

Reflow and repaint

Reflow

concept:

When part or all of the render tree changes due to changes in the structure, size, layout, etc. of the elements, the browser re-renders part or all of the DOM.

Emphasize that the position and distance of element nodes have changed.

Actions that cause reflux:

  • The browser window size changes
  • Content changes
  • Add or remove nodes
  • Activate CSS pseudo-classes
  • etc…

Redraw

concept:

When the style of a page element changes without affecting its position in the document flow, the browser simply assigns the new style to the element and repaints it.

Emphasize the style of element nodes, such as color, border solid line becomes dashed line (without changing position and distance).

Operations that cause redrawing:

  • When the background-color property value changes
  • When the border-color property value changes
  • When the visibility attribute value changes
  • etc…

insert image description here

The above is the detailed content of the principles and differences of reflow and repaint, which are frequently asked in Web interviews. For more information about reflow and repaint in Web interviews, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to reduce browser reflow and repaint
  • Detailed explanation of Repaint and Reflow usage in JavaScript
  • JavaScript performance optimization (repaint and reflow)
  • High-performance WEB development page rendering, redrawing, and reflow.

<<:  How to use libudev in Linux to get USB device VID and PID

>>:  How to connect to MySQL remotely through Navicat

Recommend

Count the list tags in HTML

1. <dl> defines a list, <dt> defines ...

Priority analysis of and or queries in MySQL

This may be an issue that is easily overlooked. F...

Vue song progress bar sample code

Note that this is not a project created by vue-cl...

Create an SSL certificate that can be used in nginx and IIS

Table of contents Creating an SSL Certificate 1. ...

VUE + OPENLAYERS achieves real-time positioning function

Table of contents Preface 1. Define label style 2...

MySQL encryption and decryption examples

MySQL encryption and decryption examples Data enc...

How to use MySQL stress testing tools

1. MySQL's own stress testing tool - Mysqlsla...

How to use history redirection in React Router

In react-router, the jump in the component can be...

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

Web standards learning to understand the separation of structure and presentation

When discussing Web standards, one thing that alwa...

Detailed steps to start the Django project with nginx+uwsgi

When we develop a web project with Django, the te...

Hbase Getting Started

1. HBase Overview 1.1 What is HBase HBase is a No...

Tutorial on downloading, installing, configuring and using MySQL under Windows

Overview of MySQL MySQL is a relational database ...