Slide 1

Slide 1 text

The Critical Request Ben Schwarz @benschwarz !

Slide 2

Slide 2 text

calibreapp.com

Slide 3

Slide 3 text

Performance status quo Follow the rules you know and love • Serve less requests • Use compression everywhere possible (Brotli, GZip) • Bundle and minimise scripts (UglifyJS) • Use asset hashing (app-0ff97b5.js), with “forever” cache headers • Use CDNs (Fastly, Netlify, Cloudflare, Cloudfront)

Slide 4

Slide 4 text

Performance through the eyes of your users. 1.

Slide 5

Slide 5 text

Users lose focus after 1 second. Abandonment rises dramatically after 10 seconds.

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

User navigates

Slide 8

Slide 8 text

User navigates

Slide 9

Slide 9 text

User navigates First Paint

Slide 10

Slide 10 text

User navigates First Paint

Slide 11

Slide 11 text

User navigates First Paint

Slide 12

Slide 12 text

User navigates First Paint First Contentful Paint

Slide 13

Slide 13 text

User navigates First Paint First Contentful Paint

Slide 14

Slide 14 text

User navigates First Paint First Contentful Paint

Slide 15

Slide 15 text

User navigates First Paint First Contentful Paint First Meaningful Paint

Slide 16

Slide 16 text

User navigates First Paint First Contentful Paint First Meaningful Paint

Slide 17

Slide 17 text

User navigates First Paint First Contentful Paint First Meaningful Paint

Slide 18

Slide 18 text

Load + Render Timeline

Slide 19

Slide 19 text

Load + Render Timeline

Slide 20

Slide 20 text

onLoad Load + Render Timeline

Slide 21

Slide 21 text

onLoad First Meaningful Paint Load + Render Timeline

Slide 22

Slide 22 text

onLoad First Meaningful Paint Load + Render Timeline

Slide 23

Slide 23 text

Focus on these requests onLoad First Meaningful Paint Load + Render Timeline

Slide 24

Slide 24 text

onLoad First Meaningful Paint First Meaningful Paint Text & Lead content has been rendered

Slide 25

Slide 25 text

← Critical requests A critical request is one that contains an asset that is essential to the content within the users viewport

Slide 26

Slide 26 text

Often, these are: 1. CSS for the elements 
 on the page 2. Fonts 3. Logo 4. A lead image ← Critical requests A critical request is one that contains an asset that is essential to the content within the users viewport

Slide 27

Slide 27 text

How do browsers decide which resources should be fetched? 2.

Slide 28

Slide 28 text

Resource queuing

Slide 29

Slide 29 text

My website … Resource queuing

Slide 30

Slide 30 text

My website … Resource queuing Queue

Slide 31

Slide 31 text

My website … app.css Resource queuing Queue

Slide 32

Slide 32 text

My website … app.css app.js Resource queuing Queue

Slide 33

Slide 33 text

My website … app.css app.js font.woff Resource queuing Queue

Slide 34

Slide 34 text

Inspecting request priority

Slide 35

Slide 35 text

Inspecting request priority

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest … and how they are referenced

Slide 39

Slide 39 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest • HTML (Highest) … and how they are referenced

Slide 40

Slide 40 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest • HTML (Highest) • Styles (Highest) … and how they are referenced

Slide 41

Slide 41 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest • HTML (Highest) • Styles (Highest) • Images (Low or Medium) … and how they are referenced

Slide 42

Slide 42 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest • HTML (Highest) • Styles (Highest) • Images (Low or Medium) • XHR/Fetch (High) … and how they are referenced

Slide 43

Slide 43 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest • HTML (Highest) • Styles (Highest) • Images (Low or Medium) • XHR/Fetch (High) • Fonts (Highest) … and how they are referenced

Slide 44

Slide 44 text

app.css app.js font.woff Assets are prioritised by type Queue Highest High Lowest • HTML (Highest) • Styles (Highest) • Images (Low or Medium) • XHR/Fetch (High) • Fonts (Highest) • Scripts (Low, Medium or High!) … and how they are referenced

Slide 45

Slide 45 text

Javascript request priorities For an in depth guide, see https://www.html5rocks.com/en/tutorials/speed/script-loading/ by @jaffathecake High (when placed before ) Otherwise, Medium Low Priority

Slide 46

Slide 46 text

How fonts are fetched

Slide 47

Slide 47 text

How fonts are fetched 1. The stylesheet targets an element with a font declaration body { font-family: Calibre; }

Slide 48

Slide 48 text

How fonts are fetched 1. The stylesheet targets an element with a font declaration body { font-family: Calibre; } 2. The stylesheet has a corresponding @font-face declaration @font-face { font-family: "Calibre"; src: url("/fonts/calibre.woff2") format("woff2"), url("/fonts/calibre.woff") format("woff"); }

Slide 49

Slide 49 text

How fonts are fetched 1. The stylesheet targets an element with a font declaration body { font-family: Calibre; } 3. There is text to render 2. The stylesheet has a corresponding @font-face declaration @font-face { font-family: "Calibre"; src: url("/fonts/calibre.woff2") format("woff2"), url("/fonts/calibre.woff") format("woff"); }

Slide 50

Slide 50 text

Auditing and improving performance. 3.

Slide 51

Slide 51 text

Auditing atlassian.com

Slide 52

Slide 52 text

Test using poor conditions

Slide 53

Slide 53 text

Test using poor conditions

Slide 54

Slide 54 text

Create a performance trace

Slide 55

Slide 55 text

Create a performance trace

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Preload Critical, essential resources. Required for fonts! HTML

Slide 59

Slide 59 text

Preload Critical, essential resources. Required for fonts! HTML Link: ; rel=preload; as=font; crossorigin As a HTTP Header

Slide 60

Slide 60 text

Local overrides

Slide 61

Slide 61 text

Local overrides

Slide 62

Slide 62 text

Use preload for critical resources Every browser that supports preload also supports WOFF. Preload those!

Slide 63

Slide 63 text

HTML CSS Font Weight 1 Font Weight 2 Font Weight 3 Network timeline Text gets rendered here Before preload 5-7 seconds until text is visible

Slide 64

Slide 64 text

HTML CSS Font Weight 1 Font Weight 2 Font Weight 3 Network timeline After preload 2-3 seconds until text is visible

Slide 65

Slide 65 text

HTML CSS Font Weight 1 Font Weight 2 Font Weight 3 Network timeline After preload 2-3 seconds until text is visible Text gets rendered here

Slide 66

Slide 66 text

@font-face { font-family: LLCircularWeb; src: url(/lineto-circular-black-c.woff) format("woff"); font-weight: 800; font-style: normal; font-display: swap;
 } Add font-display: swap “ Display the text until the web font has loaded, then swap it out.

Slide 67

Slide 67 text

HTML Network timeline Before font-display 2-3 seconds until text is visible HTML CSS Font Weight 1 Font Weight 2 Font Weight 3

Slide 68

Slide 68 text

HTML Network timeline Before font-display 2-3 seconds until text is visible HTML CSS Font Weight 1 Font Weight 2 Font Weight 3 Text gets rendered here

Slide 69

Slide 69 text

HTML CSS Font Weight 1 Font Weight 2 Font Weight 3 Network timeline After font-display Text is always visible

Slide 70

Slide 70 text

HTML CSS Font Weight 1 Font Weight 2 Font Weight 3 Network timeline After font-display Text is always visible Text gets rendered here

Slide 71

Slide 71 text

Font style matcher https://meowni.ca/font-style-matcher/ Monica Dinculescu @notwaldorf

Slide 72

Slide 72 text

Font style matcher https://meowni.ca/font-style-matcher/ Monica Dinculescu @notwaldorf

Slide 73

Slide 73 text

Audit improvement notes

Slide 74

Slide 74 text

Audit improvement notes 1. Use to preload essential fonts.

Slide 75

Slide 75 text

Audit improvement notes 1. Use to preload essential fonts. 2. Use font-display: swap; to ensure text is always visible.

Slide 76

Slide 76 text

Audit improvement notes 1. Use to preload essential fonts. 2. Use font-display: swap; to ensure text is always visible. 3. Have font fallbacks that look similar to avoid changes when webfonts load.

Slide 77

Slide 77 text

Audit improvement notes 1. Use to preload essential fonts. 2. Use font-display: swap; to ensure text is always visible. 3. Have font fallbacks that look similar to avoid changes when webfonts load. 4. Use woff2, woff where possible.

Slide 78

Slide 78 text

Priority Hints github.com/WICG/priority-hints await fetch(‘api/endpoint.json’, {importance: ‘low’}) Experimental

Slide 79

Slide 79 text

Audit checklist

Slide 80

Slide 80 text

Audit checklist 1. Test under poor conditions to highlight performance issues.

Slide 81

Slide 81 text

Audit checklist 1. Test under poor conditions to highlight performance issues. 2. Use the performance panel to explore the relationship between render, asset fetching, paints and JavaScript execution.

Slide 82

Slide 82 text

Audit checklist 1. Test under poor conditions to highlight performance issues. 2. Use the performance panel to explore the relationship between render, asset fetching, paints and JavaScript execution. 3. Ensure critical requests are prioritised.

Slide 83

Slide 83 text

Audit checklist 1. Test under poor conditions to highlight performance issues. 2. Use the performance panel to explore the relationship between render, asset fetching, paints and JavaScript execution. 3. Ensure critical requests are prioritised. 4. Iterate from good to great.

Slide 84

Slide 84 text

Audit checklist 1. Test under poor conditions to highlight performance issues. 2. Use the performance panel to explore the relationship between render, asset fetching, paints and JavaScript execution. 3. Ensure critical requests are prioritised. 4. Iterate from good to great.

Slide 85

Slide 85 text

Becoming a successful performance advocate at your company. 4.

Slide 86

Slide 86 text

Project timeline Performance usually happens here

Slide 87

Slide 87 text

Project timeline “Hey, is the website fast?” “ahhhh, um…”

Slide 88

Slide 88 text

Project timeline “Let’s make this really great!” When performance should happen

Slide 89

Slide 89 text

It ain't done until it's fast It ain't done until it's accessible

Slide 90

Slide 90 text

… Can we schedule some more performance work? I have no idea how long it’ll take but we’ll hope for the best! Your manager You, without a plan

Slide 91

Slide 91 text

Performance workbook

Slide 92

Slide 92 text

Performance workbook

Slide 93

Slide 93 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost

Slide 94

Slide 94 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost Preload fonts 3 — 5 seconds FMP 3 seconds to FMP Easy Low

Slide 95

Slide 95 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost Preload fonts 3 — 5 seconds FMP 3 seconds to FMP Easy Low Font-display: swap Instant text rendering Instant text rendering Easy Low

Slide 96

Slide 96 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost Preload fonts 3 — 5 seconds FMP 3 seconds to FMP Easy Low Font-display: swap Instant text rendering Instant text rendering Easy Low Remove all webfonts Less download? ? Political hurdles with branding team

Slide 97

Slide 97 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost Preload fonts 3 — 5 seconds FMP 3 seconds to FMP Easy Low Font-display: swap Instant text rendering Instant text rendering Easy Low Remove all webfonts Less download? ? Political hurdles with branding team Rewrite app in React ? ? Hard Very expensive

Slide 98

Slide 98 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost Preload fonts 3 — 5 seconds FMP 3 seconds to FMP Easy Low Font-display: swap Instant text rendering Instant text rendering Easy Low Remove all webfonts Less download? ? Political hurdles with branding team Rewrite app in React ? ? Hard Very expensive Remove ads 10 seconds time to interactive improvement on mobile devices ? Medium All our revenue

Slide 99

Slide 99 text

Performance workbook Estimated gain Achieved gain Difficulty Estimated cost Preload fonts 3 — 5 seconds FMP 3 seconds to FMP Easy Low Font-display: swap Instant text rendering Instant text rendering Easy Low Remove all webfonts Less download? ? Political hurdles with branding team Rewrite app in React ? ? Hard Very expensive Remove ads 10 seconds time to interactive improvement on mobile devices ? Medium All our revenue Delete all Javascript No JS, no problems ? Easy

Slide 100

Slide 100 text

Sure Can we schedule some more performance work? I’ve summarised some research and ideas in this spreadsheet… I can run you through the details over a coffee? Your manager You, an intellectual

Slide 101

Slide 101 text

The performance advocate’s manifesto

Slide 102

Slide 102 text

The performance advocate’s manifesto 1. Performance is a baseline requirement.

Slide 103

Slide 103 text

The performance advocate’s manifesto 1. Performance is a baseline requirement. 2. Every addition has a cost, therefore it should have a value.

Slide 104

Slide 104 text

The performance advocate’s manifesto 1. Performance is a baseline requirement. 2. Every addition has a cost, therefore it should have a value. 3. Performance testing should be automated.

Slide 105

Slide 105 text

The performance advocate’s manifesto 1. Performance is a baseline requirement. 2. Every addition has a cost, therefore it should have a value. 3. Performance testing should be automated. 4. Draw conclusions and act on observed performance data.

Slide 106

Slide 106 text

The performance advocate’s manifesto 1. Performance is a baseline requirement. 2. Every addition has a cost, therefore it should have a value. 3. Performance testing should be automated. 4. Draw conclusions and act on observed performance data.

Slide 107

Slide 107 text

calibreapp.com

Slide 108

Slide 108 text

@benschwarz Cheers calibreapp.com