Skip to content

Html Reflow and Layout Thrashing

wangb edited this page Apr 9, 2018 · 2 revisions

What cause the browser reflow:

Element
  • clientHeight
  • clientLeft
  • clientTop
  • clientWidth
  • focus
  • getBoundingClientRect
  • getClientRects
  • innerText
  • offsetHeight
  • offsetLeft
  • offsetParent
  • offsetTop
  • offsetWidth
  • outerText
  • scrollByLines
  • scrollByPages
  • scrollHeight
  • scrollIntoView
  • scrollIntoViewIfNeeded
  • scrollLeft
  • scrollTop
  • scrollWidth

MouseEvent

  • layerX
  • layerY
  • offsetX
  • offsetY

Window

  • getComputedStyle
  • scrollBy
  • scrollTo
  • scrollX
  • scrollY

Frame, Document & Image

  • height
  • width

How to fix

  • quick fix: re-order the execution so that we can batch the DOM reads and DOM writes together.
  • requestAnimationFrame (raf): an example show that raf can prevent layout thrashing. But it still need to manually re-order the execution. And in raf function the layout thrashing problem still exist.
  • FastDom: isolation read and write jobs.
  • virtual dom
Clone this wiki locally