Slide 1

Slide 1 text

Statically Generating Performance Tim Brown @_brimtown

Slide 2

Slide 2 text

Tim Brown @_brimtown

Slide 3

Slide 3 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 4

Slide 4 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Goals Deliver a mobile-first, highly interactive experience

Slide 8

Slide 8 text

Our Needs We knew we needed scalability and web performance

Slide 9

Slide 9 text

Web Performance Impacts ecommerce conversion rate and SEO

Slide 10

Slide 10 text

harrys.com (2013 – present )

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Original Stack Launched on Magento, rewritten in Rails

Slide 13

Slide 13 text

Harry’s Architecture Monolith, frontend and backend coupled together

Slide 14

Slide 14 text

Inflection Point Main focus on scalability and server performance

Slide 15

Slide 15 text

Server Performance

Slide 16

Slide 16 text

Harry’s Page Rendering Some pages written in Rails ERB templates

Slide 17

Slide 17 text

Harry’s Page Rendering More interactive pages written with MooTools, then React

Slide 18

Slide 18 text

Harry’s Page Rendering As more UI moved to React, noticed more layout jank

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Deeper Understanding Time to rethink performance, starting with page rendering

Slide 21

Slide 21 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 22

Slide 22 text

Server-Side Rendering Traditional Rendering

Slide 23

Slide 23 text

Server Rendering Architecture User

Slide 24

Slide 24 text

Server Rendering Architecture User Server

Slide 25

Slide 25 text

Server Rendering Architecture User Server GET harrys.com/blades

Slide 26

Slide 26 text

Server Rendering Architecture User Server GET harrys.com/blades Data

Slide 27

Slide 27 text

Server Rendering Architecture User Server GET harrys.com/blades Data Page Templates

Slide 28

Slide 28 text

Server Rendering Architecture blades.html User Server GET harrys.com/blades Data Page Template s Page Templates

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Server Rendering Architecture blades.html User Server GET harrys.com/blades Data Page Template s Page Templates

Slide 31

Slide 31 text

Server Rendering Architecture blades.html Data User Server GET harrys.com/blades Page Template s Page Templates

Slide 32

Slide 32 text

Server Rendering: Pros Complexity scales to large numbers of pages ✅

Slide 33

Slide 33 text

Server Rendering: Pros Quick initial render of the page ✅

Slide 34

Slide 34 text

First Meaningful Paint (FMP) Time it takes for the primary above-the-fold content to render

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Server Rendering: Cons Server infrastructure needs to scale with traffic ❌

Slide 37

Slide 37 text

Server Rendering Architecture blades.html Data User Server GET harrys.com/blades Page Template s Page Templates

Slide 38

Slide 38 text

Server Rendering: Cons Takes time to generate a page on the fly ❌

Slide 39

Slide 39 text

Time To First Byte (TTFB) Time between the request being made and initial data being received

Slide 40

Slide 40 text

Server Rendering Architecture blades.html Data User Server GET harrys.com/blades Page Template s Page Templates Time to First Byte (TTFB)

Slide 41

Slide 41 text

Time to First Byte Distance from server (latency) also affects TTFB

Slide 42

Slide 42 text

Client-Side Rendering Traditional Rendering

Slide 43

Slide 43 text

Server-Side Rendering Architecture blades.html Data User Server GET harrys.com/blades Page Template s Page Templates

Slide 44

Slide 44 text

Client-Side Rendering Architecture blades.html Data User Server GET harrys.com/blades Page Template s Page Templates bundle.js

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Client-Side Rendering: Pros Author pages with JavaScript frameworks ✅

Slide 48

Slide 48 text

Client-Side Rendering: Pros Ability to decouple frontend and backend ✅

Slide 49

Slide 49 text

Client-Side Rendering: Cons First Meaningful Paint can be slower than plain HTML ❌

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Page Weight JavaScript is the single most expensive asset you can ship

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Client-Side Rendering: Cons Page interactivity can suffer with too much JavaScript ❌

Slide 54

Slide 54 text

Time To Interactive (TTI) Time it takes for the page to be ready to respond to user input

Slide 55

Slide 55 text

Server-Side Client-Side Serving (TTFB) ✅ Rendering (FMP) ✅ ❌ Interactivity (TTI) ✅ Authoring ❌ ✅ Operations ❌ ❌

Slide 56

Slide 56 text

Flamingo Needs #1: Deliver great TTFB and FMP

Slide 57

Slide 57 text

Flamingo Needs #2: Render a small number of pages that don’t change often

Slide 58

Slide 58 text

Flamingo Needs #3: Minimize operational overhead and complexity

Slide 59

Slide 59 text

Flamingo Needs #4: Author pages entirely with React

Slide 60

Slide 60 text

Architecture Is there an alternate architecture that meets our needs?

Slide 61

Slide 61 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 62

Slide 62 text

Static Rendering Architecture Data Build Server Page Template s Page Templates

Slide 63

Slide 63 text

Static Rendering Architecture blades.html Data Build Server Page Template s Page Templates

Slide 64

Slide 64 text

Static Rendering Architecture blades.html Data Build Server Page Template s shave-set.html Page Templates

Slide 65

Slide 65 text

Static Rendering Architecture blades.html Data Build Server Page Template s shave-set.html homepage.html Page Templates

Slide 66

Slide 66 text

Static Rendering Architecture User

Slide 67

Slide 67 text

Static Rendering Architecture User GET shopflamingo.com/blades

Slide 68

Slide 68 text

Static Rendering Architecture User GET shopflamingo.com/blades blades.html shave-set.html homepage.html

Slide 69

Slide 69 text

Static Rendering Architecture User GET shopflamingo.com/blades blades.html shave-set.html homepage.html

Slide 70

Slide 70 text

Static Rendering Architecture User GET shopflamingo.com/blades blades.html shave-set.html homepage.html blades.html

Slide 71

Slide 71 text

An Analogy Restaurant vs. Catering

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Gatsby 1. Author in React 2. Render to HTML 3. Serve static files

Slide 74

Slide 74 text

Server-Side Client-Side Serving (TTFB) ✅ Rendering (FMP) ✅ ❌ Interactivity (TTI) ✅ Authoring ❌ ✅ Operations ❌ ❌

Slide 75

Slide 75 text

Server-Side Client-Side Static Serving (TTFB) ✅ ✅ Rendering (FMP) ✅ ❌ ✅ Interactivity (TTI) ✅ Authoring ❌ ✅ ✅ Operations ❌ ❌ ✅

Slide 76

Slide 76 text

Flamingo Frontend Architecture

Slide 77

Slide 77 text

Flamingo Frontend Architecture

Slide 78

Slide 78 text

Flamingo Frontend Architecture merge

Slide 79

Slide 79 text

Flamingo Frontend Architecture merge publish

Slide 80

Slide 80 text

Flamingo Frontend Architecture merge build publish

Slide 81

Slide 81 text

Flamingo Frontend Architecture merge build serve publish

Slide 82

Slide 82 text

Operational Benefits Static page generation means we can be fully “serverless”

Slide 83

Slide 83 text

Static Rendering: Pros Pushes all latency and scaling to the CDN

Slide 84

Slide 84 text

Cache Invalidation Can set very long cache times since everything is static

Slide 85

Slide 85 text

Cache Invalidation Automatically invalidate changed files on publish

Slide 86

Slide 86 text

Everything Else Many other concerns outside of just rendering

Slide 87

Slide 87 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 88

Slide 88 text

JavaScript

Slide 89

Slide 89 text

JavaScript JavaScript is the single most expensive asset you can ship

Slide 90

Slide 90 text

JavaScript: Code Splitting by Route app.js homepage.js about-us.js product--blades.js product--shave-set.js ...

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

CSS

Slide 93

Slide 93 text

CSS With traditional CSS, hard to know what’s being used

Slide 94

Slide 94 text

CSS: Code Splitting by Component Code split with styled-components, render to plain CSS

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

Images

Slide 97

Slide 97 text

Images: “Resolution Switching” Serve different images based on screen size

Slide 98

Slide 98 text

Images: srcset and sizes

Slide 99

Slide 99 text

Images: Formats Serve WebP to browsers that support it, with fallbacks

Slide 100

Slide 100 text

Images: Loading Lazy-load images below the fold to reduce page weight

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

Fonts

Slide 103

Slide 103 text

Fonts: Preloading Preload critical fonts to minimize “flash of unstyled text”

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

Fonts: Subsetting Subset fonts based on which characters are actually being used

Slide 106

Slide 106 text

Compression

Slide 107

Slide 107 text

Compression: GZIP vs. Brotli Compress assets with Brotli for ~20% smaller file sizes

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 110

Slide 110 text

Automation Automate as much performance as you can

Slide 111

Slide 111 text

Automation Automation means more time shipping features

Slide 112

Slide 112 text

Monitoring Keeping a site fast is just as important as building it fast

Slide 113

Slide 113 text

Synthetic vs. Real-User Monitoring Synthetic for trends, RUM for user insights

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

Speed as a Feature When comparing speed, 20% faster is noticeable to users

Slide 116

Slide 116 text

Flamingo First Meaningful Paint Comparison Competitors / other ecommerce

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

Metrics Prioritize metrics that are tied to user experience

Slide 119

Slide 119 text

RUM Problems Many important RUM metrics aren’t available from Safari

Slide 120

Slide 120 text

RUM Problems RUM with single-page apps means you have to define “done”

Slide 121

Slide 121 text

Process Use performance budgets to align site goals with users

Slide 122

Slide 122 text

H’istory Optimizing the Rest Traditional Rendering Automation & Measurement Static Rendering The “Why?” 1 2 3 4 5 6

Slide 123

Slide 123 text

Engineers Web performance is both quantitative and qualitative

Slide 124

Slide 124 text

Business Good web performance helps business metrics

Slide 125

Slide 125 text

Users Web performance is about users

Slide 126

Slide 126 text

Users Web performance determines which users can use your site

Slide 127

Slide 127 text

Hello there, Sincerely, [redacted] From beautiful Grand Lake, Oklahoma! “I am a very heavy online shopper. Living in a small resort town, I buy literally every single thing we need online except for fresh perishables.”

Slide 128

Slide 128 text

Hello there, Sincerely, [redacted] From beautiful Grand Lake, Oklahoma! “Your website conveyed a sense of a quick and uncomplicated transaction, and one that was built for mobile users like me.”

Slide 129

Slide 129 text

Users Building for performance allows you to serve all users

Slide 130

Slide 130 text

Thank You Tim Brown @_brimtown