ContentsThe library

How a Browser Draws a Page

Four Things Stand Between a Document Arriving and Anything Appearing, and Only One of Them Is Usually the Reason Your Page Is Slow

Last timeWorking Out What Applies

The complete list of what prevents the first frame, what each one costs in practice, and the three questions that tell you which item is actually holding your page.

The complete list

Two lessons have each produced one reason the page is not on the screen yet.

Collecting them gives a list that is shorter than most people expect.

A stylesheet whose conditions apply blocks, because a rule in it could change

any position, as the previous lesson established.

A script with no attribute blocks, because the parser cannot continue past it,

so the tree stops growing and the rest of the document is not even known about.

The document itself blocks, in the sense that nothing can be drawn before

enough of it has arrived to contain something worth drawing.

And a web font blocks the text that uses it, which is a narrower kind of

blocking and the one that produces the most confusing symptom.

That is the list. Four categories.

FIG 1What each kind of resource holds up
stops the tree growingstops layout runningstops something being dr
stylesheet that applies 111
script with no attribute111
web font in visible text001
image in the visible are000
image further down the p000
script marked defer000
stylesheet for printing 000
The top two rows fill every column and the bottom four fill none. The first marked cell is the only resource that stops the tree itself, which is why it is the most damaging, and the second marked cell is the one people most often expect to be filled and it is not: an image in view delays nothing, it simply appears when it arrives.

Which one is actually costing you

The four are not comparable in cost, and this is where most optimisation effort

is misspent. The useful move is to find the one on the critical path and leave

the others alone.

FIG 2Four blocking items on one page, measured
stepitemwhen it was discoveredwhen it finisheddelay it addedwhat happened
1the document0180180One round trip plus the server working. Unavoidable and the floor under everything else.
2the stylesheet190410220Found in the first packet, which is the good case. Still a full round trip, and the first frame cannot precede it.
3a script in the head195690280Discovered at the same moment and finished much later, because it is larger and because the parser stopped while it ran. This is the item on the critical path.
4the heading font43076070Not discovered until the stylesheet was parsed, because the reference is inside it. The delay it adds is small because most of its fetch overlapped the script.
4 steps
Read the last column. The script contributes more than the stylesheet despite arriving at the same time, and the font contributes least despite finishing last, because its fetch ran alongside something slower. Only the third row is worth acting on, and acting on the fourth would change nothing.

Two patterns recur often enough to check first.

A script in the head with no attribute. Adding one attribute removes it from

the list entirely, and on many pages that is the whole fix.

A stylesheet reference that is not in the first packet of the document. It

cannot be fetched before it is seen, so a reference a few kilobytes down the

document starts a round trip late and everything else follows.

The lesson stops here

4 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 Slowyou are here
  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 Matteropening only
  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