Building Fast Websites Against All Odds

A presentation at DevDay 2018 in May 2018 in Berlin, Germany by Ryan Townsend

Slide 1

Slide 1

DevDay, Berlin 2018 Building fast websites against all odds Photo by Emil Vilsek on Unsplash

Slide 2

Slide 2

Who am I? Ryan Townsend CTO, SHIFT – @ryantownsend

Slide 3

Slide 3

Slide 4

Slide 4

Performance is pretty important… ‘Why Fast Matters’ by @csswizardry – https://bit.ly/2kiVDAz

Slide 5

Slide 5

Traffic x Conversion Rate x AOV

!!!

Slide 6

Slide 6

Performance = Traffic

Slide 7

Slide 7

“The result of rebuilding our pages for performance led to [...] a 15 percent increase in SEO traffic” – Pinterest Source – https://bit.ly/2ICPv4Z

Slide 8

Slide 8

“[…] starting in July 2018, page speed will be a ranking factor for mobile searches.” – Google Source – https://bit.ly/2Dt5Plz

Slide 9

Slide 9

Performance = Conversion

Slide 10

Slide 10

“For every 100ms decrease in homepage load speed, Mobify's customer base saw a 1.11% lift in session based conversion, amounting to an average annual revenue increase of $376,789” – Mobify Source – https://bit.ly/2s0FDHS

Slide 11

Slide 11

“Similarly, for every 100ms decrease in checkout page load speed, Mobify's customers saw a 1.55% lift in session based conversion, amounting to an average annual revenue increase of $526,147” – Mobify Source – https://bit.ly/2s0FDHS

Slide 12

Slide 12

Performance = AOV

Slide 13

Slide 13

+9.6% pages/session

Slide 14

Slide 14

+8.7% AOV

Slide 15

Slide 15

Performance x Performance x Performance = !!!

Slide 16

Slide 16

But it’s not that easy…

Slide 17

Slide 17

Selling performance can be tricky

Slide 18

Slide 18

“Can you implement AMP?”

Slide 19

Slide 19

• Replica of your site • Restricted HTML: limited AMP elements • Restricted JS: no custom JS allowed • Restricted CSS: inlined, 50kb max • No repaint: fixed element sizing • No desktop: mobile-only • Shown within Google’s branding • Stale-while-revalidate: minimum 15 seconds refresh • Extra QA effort

Slide 20

Slide 20

It’s gonna get expensive

Slide 21

Slide 21

“But the carousel!”

Slide 22

Slide 22

Slide 23

Slide 23

“[…] we now feel ready to take the next step and work to support more instant-loading content not based on AMP technology in areas of Google Search designed for this, like the Top Stories carousel” – AMP Project @ Google Source – https://bit.ly/2JakbtC

Slide 24

Slide 24

Why don’t we just build fast sites in the first place?

Slide 25

Slide 25

Smithsonian Institution Neg. 83-14878. “It's easier to ask forgiveness than it is to get permission.” – Grace Hopper

Slide 26

Slide 26

You don’t need permission to build fast websites

Slide 27

Slide 27

The Slowest Site in the World

Slide 28

Slide 28

github.com/ryantownsend/slowest-site-in-the-world

Slide 29

Slide 29

Slide 30

Slide 30

h t t ps://w w w.we bpage te s t.org/e asy

Slide 31

Slide 31

Initial Results? • Start render: 6.4s • SpeedIndex: 12717 • Interactive: 4.4s • Bandwidth: 2,594 KB

Slide 32

Slide 32

Slide 33

Slide 33

Connection 2.

<head> 3. CSS 4. Webfonts 5. JavaScript 6. Images

Slide 34

Slide 34

Connection

Slide 35

Slide 35

Yo u ca n’ t c o nt ro l yo u r i n f ra st r u c t u re w it h o u t
permission, but you can check features are enabled: • GZIP / Brotli • OCSP for SSL • HTTP/2 • Connection: keep-alive

Slide 36

Slide 36

<head>

Slide 37

Slide 37

Correct Order 1.

<meta> character encoding / viewport 2. <title> 3. Resource hints 4. Inline <script> 5. External stylesheet 6. Inline <style> 7. External <script> 8. Anything else, e.g. other meta tags Source – @csswizardry

Slide 38

Slide 38

Resource Hints • DNS Prefetch • Preconnect (CDN, 3rd parties) • Prefetch • Preload (CSS @imports, @font-face etc)

Slide 39

Slide 39

Slide 40

Slide 40

Progressive-enhancement, solid support

Slide 41

Slide 41

Progressive-enhancement, solid support

Slide 42

Slide 42

Results?

Slide 43

Slide 43

Start Render SpeedIndex Interactive Bandwidth (- 1 . 8 s ) (+ 1 8 4 ) (- 0 .1 s ) (no change) Value: $6,782,202 / year Value based on Mobify case study

Slide 44

Slide 44

CSS

Slide 45

Slide 45

Remove @import

Slide 46

Slide 46

Inline (Critical) CSS

Slide 47

Slide 47

Asynchronous below-the-fold CSS

Slide 48

Slide 48

Results?

Slide 49

Slide 49

Start Render SpeedIndex Interactive Bandwidth (- 0 .1 s ) (-348) (- 0 . 2 s ) (no change) Value: $376,789 / year Value based on Mobify case study (ide al condi t ions)

Slide 50

Slide 50

Start Render SpeedIndex Interactive Bandwidth (- 9 0 .1 s ) (- ∞ ) (- 0 . 2 s ) (no change) Value: $339,486,889 / year Value based on Mobify case study (G o ogle Fon ts offline )

Slide 51

Slide 51

Start Render SpeedIndex Interactive Bandwidth (- 9 0 .1 s ) (- ∞ ) (- 0 . 2 s ) (no change) Value: $38,754 / hour Value based on Mobify case study (G o ogle Fon ts offline )

Slide 52

Slide 52

Webfonts

Slide 53

Slide 53

Self-host

Slide 54

Slide 54

font-display: swap / optional

Slide 55

Slide 55

Progressive-enhancement, average support

Slide 56

Slide 56

WOFF2

Slide 57

Slide 57

Solid support, WOFF1 for IE9-IE11

Slide 58

Slide 58

unicode-range (bundling f or we b f on ts)

Slide 59

Slide 59

/* latin */ @font-face { font-family: 'Montserrat'; font-style: normal; font-weight: 400; src: local('Montserrat Regular'), local(‘Montserrat-Regular'), url(/fonts/montserrat.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;

font-display: swap;

}

Slide 60

Slide 60

Results?

Slide 61

Slide 61

Start Render SpeedIndex Interactive Bandwidth (- 1 . 8 s ) (-2 5 8 ) (- 0 .1 s ) (no change) Value: $6,782,202 / year Value based on Mobify case study

Slide 62

Slide 62

JavaScript

Slide 63

Slide 63

Sync vs Async vs Defer s t ill v aluable ! to be avoide d!

Slide 64

Slide 64

Don’t let third parties control your performance or uptime

Slide 65

Slide 65

https://cdnjs.cloudflare.com/ajax/ libs/jquery/3.3.1/jquery.min.js (to be avoide d!)

Slide 66

Slide 66

Source – https://bit.ly/2ij5XIt

Slide 67

Slide 67

Bundling & Tree-shaking

Slide 68

Slide 68

Results?

Slide 69

Slide 69

Start Render SpeedIndex Interactive Bandwidth (- 0 .1 s ) (- 6 9 1 ) (-2 . 2 s ) (-5KB) Value: $376,789 / year Value based on Mobify case study

Slide 70

Slide 70

Images

Slide 71

Slide 71

Foreground vs Background

Slide 72

Slide 72

<img src=“image.jpg” /> background-image: url(image.jpg) vs

Slide 73

Slide 73

Hero loaded after lower-priority product images

Slide 74

Slide 74

Corrected by using a foreground <img>

Slide 75

Slide 75

Lazy-load Beneath the Fold

Slide 76

Slide 76

Slide 77

Slide 77

Slide 78

Slide 78

Source – medium.com Lo w-Quali t y Image Pre v ie w (LQ IP)

Slide 79

Slide 79

Source – medium.com Lo w-Quali t y Image Pre v ie w (LQ IP)

Slide 80

Slide 80

Serve Appropriate Sizes

Slide 81

Slide 81

Latest version of all the major browsers

Slide 82

Slide 82

Serve Appropriate Formats

Slide 83

Slide 83

Blink-based browsers only "

Slide 84

Slide 84

Safari only "

Slide 85

Slide 85

IE/Edge only "

Slide 86

Slide 86

<picture> <!--[if IE 9]><video style=&#34;display: none;><![endif]-->
	<source	

srcset='hero@1600w.jxr 1600w, ...'

type='image/vnd.ms-photo' /> <source srcset='hero@1600w.jp2 1600w, ...'

type='image/jp2' /> <source srcset='hero@1600w.webp 1600w, ...'

type='image/webp' />

<!--[if IE 9]></video><![endif]-->
	<img	

srcset=' hero@1600w.jpg 1600w, hero@1400w.jpg 1400w, hero@1200w.jpg 1200w, ...'

src='hero@400w.jpg'

			alt=&#39;Hero	Image&#39;	
	/>	
</picture> our dif fe re n t f or mats our dif fe re n t size s f allb ack to JPEG w i t h an old-sch o ol <img> ‘src’

Slide 87

Slide 87

Results?

Slide 88

Slide 88

Start Render SpeedIndex Interactive Bandwidth (- 1 . 7 s ) (- 6 9 4 8 ) (- 0 .1 s ) (-2,224KB) Value: $6,405,413 / year Value based on Mobify case study

Slide 89

Slide 89

https://images.guide/

Slide 90

Slide 90

Show me the money…

Slide 91

Slide 91

Start Render SpeedIndex Interactive Bandwidth (- 3 . 8 s ) (- 8 4 8 6 ) (-2 .1 s ) (-2,229KB) Value: $14,317,982 / year Value based on Mobify case study

Slide 92

Slide 92

Original Optimised https://bit.ly/2IViWzf

Slide 93

Slide 93

What about Dev Day 2018?

Slide 94

Slide 94

Start Render SpeedIndex Interactive Bandwidth (- 1 . 7 s ) (-2335) (- 5 . 2 s ) (-3,105KB) Value: $6,405,413 / year Value based on Mobify case study

Slide 95

Slide 95

323,000 tickets

Slide 96

Slide 96

https://bit.ly/2L6LW3T

Slide 97

Slide 97

Low-hanging fruit can have immense impact on performance

Slide 98

Slide 98

Bonus Point!

Slide 99

Slide 99

Service Workers

Slide 100

Slide 100

Latest version of all the major browsers

Slide 101

Slide 101

• Progressive enhancement • Network control • Offline support • Progressive Web Apps (PWAs) • stale-while-revalidate / stale-while-error • Protect against 3rd party slow-downs

Slide 102

Slide 102

function timeout(delay){ return new Promise(function(resolve, reject) { setTimeout(function(){ resolve(new Response('', { status: 408, statusText: 'Request timed out.' })); }, delay); }); } self.addEventListener('fetch', function(event { event.respondWith(Promise.race([ fetch(event.request), timeout(2000) ])); }); at temp t t he reque s t f orce a 2-se cond t ime ou t

Slide 103

Slide 103

Thank you! Ryan Townsend CTO, SHIFT – @ryantownsend