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

GZIP compression Tomcat and improve web performance process diagram

1. Introduction I recently worked on a project an...

Enabling or disabling GTID mode in MySQL online

Table of contents Basic Overview Enable GTID onli...

Best Practices Guide for MySQL Partitioned Tables

Preface: Partitioning is a table design pattern. ...

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

Installation and configuration of MySQL 5.7.17 free installation version

MYSQL version: MySQL Community Server 5.7.17, ins...

Use tomcat to deploy SpringBoot war package in centos environment

Prepare war package 1. Prepare the existing Sprin...

Docker deploys Macvlan to achieve cross-host network communication

Basic concepts: Macvlan working principle: Macvla...

Implementation of importing and exporting docker images

Docker usage of gitlab gitlab docker Startup Comm...

Detailed explanation of efficient MySQL paging

Preface Usually, a "paging" strategy is...

Sharing tips on using scroll bars in HTML

Today, when we were learning about the Niu Nan new...

Vue + element to dynamically display background data to options

need: Implement dynamic display of option values ...