Boss lesson · Unit 02
The first paint
One article page: clear the path from HTML to pixels
What you practise
- Render-blocking CSS and scripts,
preloadandpreconnect, fonts that do not hide text, inlining what the first screen needs
Try a question from this lesson
Pick one
The article text is inside the HTML, which arrived at 0.3 s. Why was nothing painted until 1.5 s?
<head> links site.css, print.css
and <script src="stats.js">
0.0-0.3 s article.html
0.3-0.7 s site.css
0.3-0.6 s print.css
0.3-1.5 s stats.js
first paint: 1.5 sHint
Compare the first paint time with the time each file finished.
Correct answer
The head's CSS and script must finish before any paint
Why
The browser will not paint without the stylesheets in the head, and a plain script stops the parser before it reaches the body. The paint lands exactly when the slowest of them, stats.js, is done. The text itself was ready at 0.3 s.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
What stands before the first paint
Painting text with no styles and restyling it a moment later would look broken, so every stylesheet in the head is render-blocking: no paint until it has arrived.
A plain <script> is parser-blocking: the HTML parser stops until the script is downloaded and has run, so content below it does not exist yet.
First paint therefore waits for the slowest blocking file. The work is to make fewer files blocking and the rest quicker to arrive.
Concept
Inline what the first screen needs
Even one blocking stylesheet costs a round trip. The styles for the top of the page can travel inside the HTML, in a <style> element, and the full stylesheet can load without blocking.
The price: inlined CSS is sent again with every page and cannot be cached by itself. Keep it to the few kilobytes the first screen uses.
<head>
<style>
/* header, headline, first
paragraph: a few KB */
</style>
</head>10 more exercises in the app
- 1× fill the blanks
- 4× multiple choice
- 2× type the answer
- 1× true or false
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.