ContentsThe library

How a Browser Draws a Page

Everything So Far Described Drawing the Page Once, and the Page Is Drawn Again Sixty Times a Second, Which Changes Which Mistakes Matter

Last timePainting, and in What Order

The repeating loop that redraws a live page, the three classes every change falls into, how much of the pipeline each one re-enters, and the budget all of it has to fit inside.

The loop

Five lessons have described building a page once. A live page is rebuilt

continuously: a scroll, a hover, a timer, a response arriving, an animation

step. Each of those can change something, and the browser has to produce a new

image in time for the next refresh of the display.

FIG 1One frame
Follow the two decision points. They are the whole lesson: a change enters the loop at one of three places and pays for everything from there down, so the useful question about any change is not whether it is cheap but where it enters.

The three classes

Every change falls into one of three classes, and the class is determined by

which property changed.

FIG 2Common changes and where they enter the loop
needs layoutneeds paintneeds assemblystages re-entered
changing a width or a he1113
adding or removing an el1113
changing the text inside1113
changing a background co0112
changing a border colour0112
changing a shadow0112
a transform on a promote0011
an opacity change on a p0011
The two marked rows are the only cheap ones, and the pattern is worth memorising rather than looked up each time: geometry costs three stages, appearance costs two, and exactly two properties cost one. Every piece of advice about smooth animation is a restatement of this table.

The middle class is more expensive than it looks, because of how far a repaint

spreads. Changing the background colour of one element means redrawing the

region that element occupies, and a region is redrawn as a whole, so everything

that overlaps it is redrawn too. A colour change on a small element behind a

large image can cost more than a colour change on a large element over a flat

ground.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Browser Starts Building the Page Before It Has Finished Reading It, and One Tag in the Wrong Place Stops the Whole Production Line
  2. 02Every Element Has a Value for Every Property Whether You Wrote One or Not, and the Browser Will Not Place a Single Box Until It Knows Them Allopening only
  3. 03Four Things Stand Between a Document Arriving and Anything Appearing, and Only One of Them Is Usually the Reason Your Page Is Slowopening only
  4. 04Width Flows Downwards and Height Flows Back Up, Which Is Why the Browser Has to Visit Every Box Twice and Why One Careless Property Makes It Visit Them Foreveropening only
  5. 05The Boxes Are Placed and Nothing Is Visible Yet, Because Drawing Them Is a Separate Job With Its Own Rules and Its Own Surprising Billopening only
  6. 06Everything So Far Described Drawing the Page Once, and the Page Is Drawn Again Sixty Times a Second, Which Changes Which Mistakes Matteryou are here
  7. 07You Reached for a Link and the Page Moved and You Pressed Something Else, and the Reason Is That the Browser Was Never Told How Big a Picture Wasopening only
  8. 08Parsing, Styling, Layout, Painting, Your Code and Every Press of a Button Take Turns on a Single Queue, and Whoever Is Holding It Is Holding Everythingopening only

Read alongside