Slide 1

Slide 1 text

RESILIENT FRONT-ENDS @andyhume jQuery UK, 2015 ARCHITECTING

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

waiting for fonts.com

Slide 8

Slide 8 text

http:// Unreliable network

Slide 9

Slide 9 text

http:// Resilient web

Slide 10

Slide 10 text

Progressive enhancement http://www.flickr.com/photos/8040811@N06/3167877765 Progressive enhancement

Slide 11

Slide 11 text

Content THREE STAGES Enhancement Leftovers

Slide 12

Slide 12 text

Content THREE STAGES Enhancement Leftovers

Slide 13

Slide 13 text

Content THREE STAGES Enhancement Leftovers

Slide 14

Slide 14 text

Content THREE STAGES Enhancement Leftovers

Slide 15

Slide 15 text

Content Enhancement Leftovers

Slide 16

Slide 16 text

Content Enhancement Leftovers

Slide 17

Slide 17 text

Time to screen Key performance metric Aiming for 1s on mobile Understand the network Understand the browser

Slide 18

Slide 18 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp

Slide 19

Slide 19 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp

Slide 20

Slide 20 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp

Slide 21

Slide 21 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp SSL Handshake

Slide 22

Slide 22 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp HTTP Redirect SSL Handshake

Slide 23

Slide 23 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp HTTP Redirect SSL Handshake

Slide 24

Slide 24 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp HTTP Redirect SSL Handshake

Slide 25

Slide 25 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp HTTP Redirect SSL Handshake

Slide 26

Slide 26 text

Time to screen: The network DNS lookup TCP connect HTTP request Server time HTTP resp HTTP Redirect SSL Handshake

Slide 27

Slide 27 text

Eliminate redirects Flush the document early Prefetch DNS But mostly, eliminate redirects Time to screen: The network

Slide 28

Slide 28 text

Time to screen: The browser Single threaded event loop 1. Construct DOM tree from HTML 2. Construct render tree from DOM tree and stylesheets 3. Layout paint

Slide 29

Slide 29 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 30

Slide 30 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 31

Slide 31 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 32

Slide 32 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 33

Slide 33 text

Blocking: remote script

Slide 34

Slide 34 text

Blocking: inline script waiting on remote CSS var rules = window.styleSheets[0].cssRules;

Slide 35

Slide 35 text

Blocking: remote script (solution 1)

Slide 36

Slide 36 text

Blocking: remote script (solution 2) var script = document.createElement('script'); script.src = "app.js"; document.head.appendChild(script);

Slide 37

Slide 37 text

Blocking: remote script (solution 2) var script = document.createElement('script'); script.src = "app.js"; document.head.appendChild(script); HIDDEN FROM PRE-PARSER!

Slide 38

Slide 38 text

Blocking: remote script (solution 3)

Slide 39

Slide 39 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 40

Slide 40 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 41

Slide 41 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 42

Slide 42 text

Time to screen: Start render HTML parser DOM tree Layout Paint Render tree

Slide 43

Slide 43 text

Blocking: fetching stylesheets

Slide 44

Slide 44 text

Blocking: fetching stylesheets (solution) // Core styles in the head of the document. body { background: grey; color: #3A2FDE; }

Slide 45

Slide 45 text

Blocking: critical CSS generators https://github.com/pocketjoso/penthouse http://jonassebastianohlsson.com/ criticalpathcssgenerator/ https://github.com/filamentgroup/criticalcss

Slide 46

Slide 46 text

Recap: What blocks render? Remote scripts that need to be executed synchronously Inline script waiting on stylesheet fetch Stylesheet fetch for relevant media type/query

Slide 47

Slide 47 text

Recap: Fault isolation …or swimlaning Avoid synchronous dependencies Uptime is not binary

Slide 48

Slide 48 text

Blocking web fonts

Slide 49

Slide 49 text

Blocking web fonts

Slide 50

Slide 50 text

Blocking web fonts HTML CSS FONT FONT FONT START RENDER

Slide 51

Slide 51 text

Blocking web fonts HTML CSS FONT FONT FONT START RENDER TEXT RENDER

Slide 52

Slide 52 text

Blocking web fonts HTML CSS FONT FONT FONT START RENDER TEXT RENDER

Slide 53

Slide 53 text

Blocking web fonts FALLBACK BLOCKING BLOCKING + TIMEOUT Internet Explorer Safari Mobile Safari Chrome Opera (Blink) Firefox Opera (Presto)

Slide 54

Slide 54 text

Web font loader Provide control over font loading Remove fonts from the critical path Make cross-browser behaviour consistent

Slide 55

Slide 55 text

Web font loader

Slide 56

Slide 56 text

Web font loader

Slide 57

Slide 57 text

Web font loader var WebFontConfig = { custom: { families: ['Clarendon', 'Clarendon Bold'], urls: ['/myfonts.css'] } };

Slide 58

Slide 58 text

Web font loader

Slide 59

Slide 59 text

Web font loader h1 { font-family: georgia, serif; } .clarendon-loaded h1 { font-family: Clarendon, georgia, serif; }

Slide 60

Slide 60 text

CSS Font Loading Module document.fonts.load(‘Clarendon’).then(function () { document.documentElement.className += ‘clarendon-loaded'; } h1 { font-family: georgia, serif; } .clarendon-loaded h1 { font-family: Clarendon, georgia, serif; }

Slide 61

Slide 61 text

http://

Slide 62

Slide 62 text

http://www.webpagetest.org/result/130908_K2_796/ Median of nine test runs

Slide 63

Slide 63 text

http://www.webpagetest.org/result/130908_K2_796/ Median of nine test runs iPhone 4, iOS 5.1

Slide 64

Slide 64 text

http://www.webpagetest.org/result/130908_K2_796/ Median of nine test runs 3G (1.6Mps, 300ms RTT) iPhone 4, iOS 5.1

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Thank-you! lanyrd.com/sddxxk @andyhume Creative Commons Licensed Attribution, Non-Commercial, Share Alike cc