What is Browser Repaint and Reflow
Repaint and Reflow Definitions
Repaint: When current element’s style (background color, font color, etc.) changes, we only need to re-render the changed element, repaint has smaller impact on browser performance, so generally not considered. Repaint situations: Changing container’s appearance style, etc., like background: black, etc. Changing appearance, not changing layout, not affecting other dom.
Reflow: Process where browser recalculates element positions and geometric structure in document to re-render part or all of document. Because reflow may cause entire dom tree reconstruction, it’s a major performance killer. An element’s reflow causes subsequent reflow of all its child elements and ancestors immediately following it in DOM.
Browser Rendering Process
Rendering: Process where browser displays HTML code in browser window according to css defined rules
Browser Parsing HTML Basic Process:
User enters URL, browser sends request to server, server returns html file
Browser loads html code, finds a tag in tags referencing external css file
Browser sends css file request, server returns this css file
Browser continues loading html code, and css file already obtained, can render page
Browser finds a tag in code referencing an image, sends request to server. At this time browser won’t wait for image download to complete, but continues rendering subsequent code
Server returns image file, because image occupies certain area, affects subsequent paragraph layout, so browser needs to go back and render this part of code
Browser finds a script tag containing a line of javascript code, quickly runs it
Javascript script executes this statement, commands browser to hide a certain element in code, tragedy, suddenly one element less, browser has to re-render this part of code
Finally