Rendering: repaint, reflow/relayout, restyle

Wow. How did I miss this incredible article on the basics of how a browser renders a page.

The rendering process

Different browsers work differently, but the following diagram gives a general idea of what happens, more or less consistently across browsers, once they’ve downloaded the code for your page.

  • The browser parses out the HTML source code (tag soup) and constructs a DOM tree - a data representation where every HTML tag has a corresponding node in the tree and the text chunks between tags get a text node representation too. The root node in the DOM tree is the documentElement (the <html> tag)
  • The browser parses the CSS code, makes sense of it given the bunch of hacks that could be there and the number of -moz, -webkit and other extensions it doesn’t understand and will bravely ignore. The styling information cascades: the basic rules are in the User Agent stylesheets (the browser defaults), then there could be user stylesheets, author (as in author of the page) stylesheets - external, imported, inline, and finally styles that are coded into the style attributes of the HTML tags
  • Then comes the interesting part - constructing a render tree. The render tree is sort of like the DOM tree, but doesn’t match it exactly. The render tree knows about styles, so if you’re hiding a div with display: none, it won’t be represented in the render tree. Same for the other invisible elements, like head and everything in it. On the other hand, there might be DOM elements that are represented with more than one node in the render tree - like text nodes for example where every line in a <p> needs a render node. A node in the render tree is called a frame, or a box (as in a CSS box, according to the box model). Each of these nodes has the CSS box properties - width, height, border, margin, etc
  • Once the render tree is constructed, the browser can paint (draw) the render tree nodes on the screen

Taken from phpied.com.
http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/

1 note

Following

  • funniest10k
  • the-absolute-funniest-posts
  • mikelernerphotography
  • attentionindustry
  • tastefullyoffensive
  • evangotlib
  • infoneer-pulse
  • merlin
  • poplipps
  • cavalier
  • redshooter
  • frezned
  • amyvernon
  • minimalistco
  • theclearlydope
  • deviantart
  • yagottabelieve
  • mashable
  • poptech
  • gregbabula
  • john
  • teaim
  • despicablealexis
  • purple-lightsaber
  • toptumbles
  • hellonewyork
  • nonprofit-design
  • plus5mace
  • wantful
  • pixel2html
  • adobegripes
  • kimjongillookingatthings
  • tuneage
  • mikehudack
  • sirmitchell
  • officialbeastieboys
  • wondertonic
  • jordanwaller
  • badassjs
  • iiiil0liiii
  • fuzzythinking
  • manxmidge
  • rosskempfolds
  • londonelek
  • bigpinots
  • hoveringartdirectors