Get Your Head Straight
Harry Roberts – @csswizardry
Slide 2
Slide 2 text
🫀The cardiocentric theory.
Slide 3
Slide 3 text
No content
Slide 4
Slide 4 text
🧠 The cephalocentric theory.
Slide 5
Slide 5 text
“[T]he heart’s one role is the transmission of the
blood and its propulsion, by means of the arteries,
to the extremities everywhere.”
—William Harvey (1578–1657AD)
If it doesn’t need to be in the head, get it out of there.
Slide 22
Slide 22 text
Remove as Much as Possible
Move low-priority scripts to the closing body tag
Utilise in-body CSS
Reduce in-head payloads—external or inlined
Kill any ine
ffi
ciencies such as redirects
Slide 23
Slide 23 text
No content
Slide 24
Slide 24 text
1.
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
Change from Previous Cumulative Improvement
-0.041 N/A
Remove Redirect
Slide 27
Slide 27 text
Self-Host Whatever You Can
Slide 28
Slide 28 text
csswz.it/self-host
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
Change from Previous Cumulative Improvement
-0.377 -0.418
Self-Hosting
Change from Previous Cumulative Improvement
+0.139 -0.279
Fix Invalid Markup
Slide 38
Slide 38 text
The Optimum Head Order*
Slide 39
Slide 39 text
1.
2.
3. preconnect
4.
5. CSS that includes @import
6. Synchronous JS
7. Synchronous CSS
8. preload
9.
10. prefetch / prerender
11. Everything else (‘SEO’ meta tags, icons, Open Graph, etc.)
Slide 40
Slide 40 text
Meta CSP Disables Preload Scanner
Slide 41
Slide 41 text
The Preload Scanner
Invented in IE8 as the ‘Speculative Pre-Parser’
A secondary, inert, download-only parser
Decouples resource discovery/download from runtime executions
Made the web a lot, lot faster
In every single modern browser
Slide 42
Slide 42 text
Before the Preload Scanner: Parse, discover, download, execute, parse, discover, download, execute, parse…
Slide 43
Slide 43 text
After the Preload Scanner: Parsing and downloading are now independent.
Slide 44
Slide 44 text
No content
Slide 45
Slide 45 text
No content
Slide 46
Slide 46 text
No content
Slide 47
Slide 47 text
1.
2. ...
3. ...
4. ...
5.
6. ...
7.
Slide 48
Slide 48 text
csswz.it/preload-scanner-src
Slide 49
Slide 49 text
1. SELECT client, COUNT(1) as PAGES_FIRST_HTML
2. FROM `httparchive.almanac.summary_response_bodies`
3. WHERE LOWER(BODY) LIKE '%
Slide 50
Slide 50 text
No content
Slide 51
Slide 51 text
Change from Previous Cumulative Improvement
-3.704 -3.983
Move CSP Meta
Slide 52
Slide 52 text
Metadata About the Page** Goes First
Slide 53
Slide 53 text
Tell the browser how to deal with the page.
Slide 54
Slide 54 text
“The element containing the character encoding declaration must be
serialized completely within the first 1024 bytes of the document.”
— §4.2.5.4 Specifying the document's character encoding
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
Don’t Hide the Title
Slide 57
Slide 57 text
Your title is o
ft
en a visitor’s very
fi
rst impression.
Slide 58
Slide 58 text
1.
2. ...
3.
4. Hello, World!
5. ...
6.
Slide 59
Slide 59 text
No content
Slide 60
Slide 60 text
1.
2. ...
3.
4. Hello, World!
5. ...
6.
Slide 61
Slide 61 text
1.
2. ...
3. Hello, World!
4.
5. ...
6.
Slide 62
Slide 62 text
No content
Slide 63
Slide 63 text
No content
Slide 64
Slide 64 text
Change from Previous Cumulative Improvement
-0.281 -4.264
Arrange Page Metadata
But beware. Synchronous JS blocks subsequent @imports†.
Slide 75
Slide 75 text
1.
2. ...
3.
4.
5. ...
6.
Slide 76
Slide 76 text
Start Render: 4.7s
Slide 77
Slide 77 text
1.
2. ...
3.
4.
5. ...
6.
Slide 78
Slide 78 text
1.
2. ...
3.
4.
5. ...
6.
Slide 79
Slide 79 text
Start Render: 2.9s
Slide 80
Slide 80 text
9.3s wait
Slide 81
Slide 81 text
No content
Slide 82
Slide 82 text
No content
Slide 83
Slide 83 text
Change from Previous Cumulative Improvement
-1.65 -5.914
Reorder CSS and JS
Slide 84
Slide 84 text
No content
Slide 85
Slide 85 text
Change from Previous Cumulative Improvement
-0.747 -6.661
Remove @imports
Slide 86
Slide 86 text
SEO and Social Goes Last
Slide 87
Slide 87 text
If Googlebot can’t
fi
nd your meta tags, it can’t
fi
nd your content.
Slide 88
Slide 88 text
No content
Slide 89
Slide 89 text
A New Order
csswz.it/gyhs-
fi
xed
Slide 90
Slide 90 text
FCP: 2.669s
Slide 91
Slide 91 text
No content
Slide 92
Slide 92 text
No content
Slide 93
Slide 93 text
No content
Slide 94
Slide 94 text
No content
Slide 95
Slide 95 text
No content
Slide 96
Slide 96 text
Computed Tomography
Slide 97
Slide 97 text
“CT and MRI scans are two methods of imaging
internal body parts […] CT scans are more
common and less expensive, but MRI
scans produce more detailed images.”
— Oesophageal Patients Association