Slide 1

Slide 1 text

Speed Index, Explained! Stefan Baumgartner | @ddprrt https://speakerdeck.com/ddprrt/speed-index-explained

Slide 2

Slide 2 text

The page has to load in under 3 seconds

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

It works on my machine!

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

The Dothraki have no word for “works on my machine”

Slide 7

Slide 7 text

Use metrics!

Slide 8

Slide 8 text

loading document.readyState loading DOMContentLoaded window.onload

Slide 9

Slide 9 text

window.performance.timing

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Speed Index

Slide 12

Slide 12 text

∫ 1 - visuallycomplete/100 0 end

Slide 13

Slide 13 text

What does this mean?

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Visually complete (%) 0 25 50 75 100 Time in Seconds 0s 1s 2s 3s 4s 5s 6s 7s 8s

Slide 20

Slide 20 text

Visually complete (%) 0 25 50 75 100 Time in Seconds 0s 1s 2s 3s 4s 5s 6s 7s 8s

Slide 21

Slide 21 text

Visually complete (%) 0 25 50 75 100 Time in Seconds 0s 1s 2s 3s 4s 5s 6s 7s 8s

Slide 22

Slide 22 text

Visually complete (%) 0 25 50 75 100 Time in Seconds 0s 1s 2s 3s 4s 5s 6s 7s 8s

Slide 23

Slide 23 text

Visually complete (%) 0 25 50 75 100 Time in Seconds 0s 1s 2s 3s 4s 5s 6s 7s 8s

Slide 24

Slide 24 text

Visually complete (%) 0 25 50 75 100 Time in Seconds 0s 1s 2s 3s 4s 5s 6s 7s 8s

Slide 25

Slide 25 text

So, how’s difference calculated?

Slide 26

Slide 26 text

- =

Slide 27

Slide 27 text

6% difference

Slide 28

Slide 28 text

5% difference

Slide 29

Slide 29 text

this is not good for the user this is

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Baseline JPEG 10%

Slide 33

Slide 33 text

Baseline JPEG 10% 50%

Slide 34

Slide 34 text

Baseline JPEG 10% 50% 100%

Slide 35

Slide 35 text

Gotcha!

Slide 36

Slide 36 text

Baseline JPEG If the image loads gradually over 1 second, it has a SpeedIndex of 500

Slide 37

Slide 37 text

Progressive JPEG 10% 50% 100%

Slide 38

Slide 38 text

Progressive JPEG The image is already ~77% complete at the beginning (it’s 23% different)

Slide 39

Slide 39 text

Progressive JPEG So if it loads gradually over 1 second, it has a SpeedIndex of 113

Slide 40

Slide 40 text

Some tricks …

Slide 41

Slide 41 text

Webfonts

Slide 42

Slide 42 text

Modern browser? Supports WOFF? Font in Storage Show Font Pre-Render

Slide 43

Slide 43 text

Modern browser? Supports WOFF? Font in Storage Show Font No Font http://crocodillon.com/blog/non-blocking-web-fonts-using-localstorage Pre-Render

Slide 44

Slide 44 text

localStorage available? Download Font Save in localStorage Show Font No Font http://crocodillon.com/blog/non-blocking-web-fonts-using-localstorage Post-Render

Slide 45

Slide 45 text

Critical Path CSS

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

blocking!

Slide 48

Slide 48 text

blocking! blocking!

Slide 49

Slide 49 text

blocking! blocking! start render

Slide 50

Slide 50 text

blocking! blocking! start render?

Slide 51

Slide 51 text

… … loadCSS(‘main.css’)

Slide 52

Slide 52 text

… … loadCSS(‘main.css’)

Slide 53

Slide 53 text

… … loadCSS(‘main.css’)

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

I’m not 100% happy with Critical Path CSS

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

There is still one thing however…

Slide 61

Slide 61 text

Speed Index should give you an idea how the user feels when using your website

Slide 62

Slide 62 text

… so why is everything done by a machine

Slide 63

Slide 63 text

… so why is everything done by a machine

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Let’s do it on the client!

Slide 70

Slide 70 text

GetRects(); GetRectTimings(); GetFirstPaint(); GetFontTime(); CalculateVisualProgress(); CalculateSpeedIndex();

Slide 71

Slide 71 text

GetRects(); GetRectTimings(); Get the visible rectangle for the things we care about. Get the timings of the resources inside

Slide 72

Slide 72 text

window.performance.timing

Slide 73

Slide 73 text

window.performance.timing getEntriesByType(‘resource’)

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

GetFirstPaint(); Calculate the timing when the browser painted first.

Slide 78

Slide 78 text

// IE and Edge window.performance.timing.msFirstPaint // Chropera var times = window.chrome.loadTimes(); times.firstPaintTime

Slide 79

Slide 79 text

// Every other browser var headURLs = {}; var headElements = doc.getElementsByTagName('head')[0].children; for (var i = 0; i < headElements.length; i++) { //get stylesheets and non-async scripts ... } // compare with resource timing var requests = win.performance.getEntriesByType("resource");

Slide 80

Slide 80 text

GetFontTime(); Check all font resources and do resource timings …

Slide 81

Slide 81 text

CalculateSpeedIndex(); Given the visual progress information, calculate the speed index.

Slide 82

Slide 82 text

resource1 firstPaint resource3 resource4 endofPaint responseStart document font

Slide 83

Slide 83 text

resource1 firstPaint resource3 resource4 endofPaint responseStart blank, 1 point per ms! gradually document font

Slide 84

Slide 84 text

var now = ruxitApi.now(); var actionId = ruxitApi.enterAction( 'Speed Index', 'speedIndex', now - RUMSpeedIndex(), null); ruxitApi.leaveAction(actionId, now); Tell your monitor solution

Slide 85

Slide 85 text

https://github.com/ddprrt/RUM-SpeedIndex

Slide 86

Slide 86 text

@ddprrt @dynatrace @ruxit