Slide 1

Slide 1 text

HTTP/2.0 101 Introduction @BastianHofmann

Slide 2

Slide 2 text

HTTP/2.0 101 Introduction 101 Switching Protocols @BastianHofmann

Slide 3

Slide 3 text

https://www.flickr.com/photos/duncan/3171592427/

Slide 4

Slide 4 text

https://commons.wikimedia.org/wiki/File:Internet1.jpg#/media/File:Internet1.jpg

Slide 5

Slide 5 text

https://www.flickr.com/photos/neilsingapore/3567378586/

Slide 6

Slide 6 text

HTTP/0.9 http://www.w3.org/Protocols/HTTP/AsImplemented.html 1991

Slide 7

Slide 7 text

HTTP/1.0 https://tools.ietf.org/html/rfc1945 1996

Slide 8

Slide 8 text

HTTP/1.1 http://tools.ietf.org/html/rfc2616 1999

Slide 9

Slide 9 text

HTTP/1.1 http://tools.ietf.org/html/rfc2616 http://tools.ietf.org/html/rfc7230 http://tools.ietf.org/html/rfc7231 http://tools.ietf.org/html/rfc7232 http://tools.ietf.org/html/rfc7235 http://tools.ietf.org/html/rfc7234 http://tools.ietf.org/html/rfc7233 2014

Slide 10

Slide 10 text

https://www.flickr.com/photos/offshore/1433329174/

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

http://www.impressivewebs.com/importance-of-website- performance-sources/

Slide 13

Slide 13 text

There are a lot of „hacks“ needed to get a web application fast

Slide 14

Slide 14 text

HTTP/2 http://tools.ietf.org/html/rfc7540 http://tools.ietf.org/html/rfc7541 2015

Slide 15

Slide 15 text

New possibilities for web applications

Slide 16

Slide 16 text

Increased performance

Slide 17

Slide 17 text

Old truths may not be valid anymore

Slide 18

Slide 18 text

Before we start

Slide 19

Slide 19 text

A few words about me

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Questions? Ask

Slide 25

Slide 25 text

http://speakerdeck.com/u/bastianhofmann

Slide 26

Slide 26 text

The anatomy of a page load

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Every request one TCP connection

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

User enters URL

Slide 31

Slide 31 text

DNS lookup

Slide 32

Slide 32 text

TCP connection

Slide 33

Slide 33 text

TLS handshake

Slide 34

Slide 34 text

This already takes time

Slide 35

Slide 35 text

DNS caching

Slide 36

Slide 36 text

Connection Keep Alive

Slide 37

Slide 37 text

TLS optimizations

Slide 38

Slide 38 text

https://istlsfastyet.com/

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Finally: HTTP

Slide 41

Slide 41 text

GET  /  HTTP/1.1   Host:  www.researchgate.net   HTTP/1.1  200  OK   Content-­‐Type:  text/plain   Content

Slide 42

Slide 42 text

HTTP request

Slide 43

Slide 43 text

GET  /home  HTTP/1.1   Host:  www.researchgate.net   pragma:  no-­‐cache   dnt:  1   accept-­‐encoding:  gzip,  deflate,  sdch   accept-­‐language:  de-­‐DE,de;q=0.8,en-­‐ US;q=0.6,en;q=0.4   user-­‐agent:  Mozilla/5.0  (Macintosh;  Intel  Mac  OS  X   10_10_4)  AppleWebKit/537.36  (KHTML,  like  Gecko)   Chrome/46.0.2478.0  Safari/537.36   accept:  text/html,application/xhtml +xml,application/xml;q=0.9,image/webp,*/*;q=0.8   cache-­‐control:  no-­‐cache   cookie:  …  

Slide 44

Slide 44 text

https://www.flickr.com/photos/40987321@N02/5580348753/

Slide 45

Slide 45 text

HTTP response

Slide 46

Slide 46 text

HTTP/1.1  200  OK   Date:  Sun,  16  Aug  2015  11:21:31  GMT   Content-­‐Type:  text/html;  charset=utf-­‐8   Transfer-­‐Encoding:  chunked   Connection:  keep-­‐alive   Cache-­‐Control:  must-­‐revalidate,  no-­‐cache,  no-­‐store,   post-­‐check=0,  pre-­‐check=0,  private   X-­‐Correlation-­‐Id:...   expires:  Thu,  19  Nov  1981  08:52:00  GMT   pragma:  no-­‐cache   X-­‐UA-­‐Compatible:  IE=Edge   X-­‐Frame-­‐Options:  SAMEORIGIN   P3P:  CP="..."   X-­‐Content-­‐Type-­‐Options:  nosniff   X-­‐XSS-­‐Protection:  1;  mode=block   Strict-­‐Transport-­‐Security:  max-­‐age=7200   Content-­‐Security-­‐Policy:  …   Content-­‐Encoding:  gzip  

Slide 47

Slide 47 text

HTML response

Slide 48

Slide 48 text

DOM parsing

Slide 49

Slide 49 text

Rendering

Slide 50

Slide 50 text

Asset fetching

Slide 51

Slide 51 text

Applying CSS

Slide 52

Slide 52 text

Executing JS

Slide 53

Slide 53 text

https://www.flickr.com/photos/hangdog/10991275/

Slide 54

Slide 54 text

Blocking HTML rendering

Slide 55

Slide 55 text

CSS

Slide 56

Slide 56 text

JS

Slide 57

Slide 57 text

HTTP/1.1 200 OK Content-Type: text/html <script src="app.js" /> <script> // some JS

Slide 58

Slide 58 text

JS can manipulate the DOM

Slide 59

Slide 59 text

Slide 60

Slide 60 text

Average page size

Slide 61

Slide 61 text

Average asset count

Slide 62

Slide 62 text

http://www.soasta.com/blog/page-bloat-average-web-page-2-mb/

Slide 63

Slide 63 text

http://httparchive.org/trends.php

Slide 64

Slide 64 text

Every request one TCP connection

Slide 65

Slide 65 text

Concurrent connection limits

Slide 66

Slide 66 text

Network congestion

Slide 67

Slide 67 text

http://www.browserscope.org/?category=network

Slide 68

Slide 68 text

Domain sharding

Slide 69

Slide 69 text

http://c5.rgstatic.net/profile.css http://c4.rgstatic.net/icon.png

Slide 70

Slide 70 text

Shards should be persistent

Slide 71

Slide 71 text

Additional handshakes and connections

Slide 72

Slide 72 text

Network congestion

Slide 73

Slide 73 text

TCP Slow Start

Slide 74

Slide 74 text

https://de.wikipedia.org/wiki/Transmission_Control_Protocol#/media/File:TCPSlowStartundCongestionAvoidance.svg

Slide 75

Slide 75 text

Ideal number of shards

Slide 76

Slide 76 text

https://codeascraft.com/2014/02/19/reducing-domain- sharding/

Slide 77

Slide 77 text

Page sizes

Slide 78

Slide 78 text

Less content

Slide 79

Slide 79 text

GZIP

Slide 80

Slide 80 text

Image compression

Slide 81

Slide 81 text

Minification

Slide 82

Slide 82 text

JS

Slide 83

Slide 83 text

CSS

Slide 84

Slide 84 text

HTML

Slide 85

Slide 85 text

Debugging problems

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

Sourcemaps

Slide 88

Slide 88 text

Less requests

Slide 89

Slide 89 text

Concatenation

Slide 90

Slide 90 text

https://c5.rgstatic.net/c/a9b943a25d126865806885d2fd94b5f9/javascript/combo/lib/yui3/ array-extras/array-extras-min.js&lib/yui3/oop/oop-min.js&lib/yui3/attribute-core/attribute- core-min.js&lib/yui3/event-custom-base/event-custom-base-min.js&lib/yui3/event-custom- complex/event-custom-complex-min.js&lib/yui3/attribute-observable/attribute-observable- min.js&lib/yui3/attribute-extras/attribute-extras-min.js&lib/yui3/attribute-base/attribute-base- min.js&lib/yui3/attribute-complex/attribute-complex-min.js&lib/yui3/base-core/base-core- min.js&lib/yui3/base-observable/base-observable-min.js&lib/yui3/base-base/base-base- min.js&lib/yui3/pluginhost-base/pluginhost-base-min.js&lib/yui3/pluginhost-config/pluginhost- config-min.js&lib/yui3/base-pluginhost/base-pluginhost-min.js&lib/yui3/classnamemanager/ classnamemanager-min.js&lib/yui3/dom-core/dom-core-min.js&lib/yui3/dom-base/dom-base- min.js&lib/yui3/selector-native/selector-native-min.js&lib/yui3/selector/selector-min.js&lib/ yui3/node-core/node-core-min.js

Slide 91

Slide 91 text

https://c5.rgstatic.net/c/a9b943a25d126865806885d2fd94b5f9/mainbundle.js

Slide 92

Slide 92 text

Spritemaps

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

How to bundle

Slide 95

Slide 95 text

Over fetching

Slide 96

Slide 96 text

90% CSS unused

Slide 97

Slide 97 text

Cache invalidation

Slide 98

Slide 98 text

Larger assets

Slide 99

Slide 99 text

Critical rendering path

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

What is visible?

Slide 102

Slide 102 text

What is critical?

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

Inline critical assets

Slide 105

Slide 105 text

Either inline always

Slide 106

Slide 106 text

Caching?

Slide 107

Slide 107 text

First request

Slide 108

Slide 108 text

HTTP/1.1 200 OK Content-Type: text/html … your critical css
content
load main.css async set cookie that other css was loaded

Slide 109

Slide 109 text

Subsequent request (if Cookie set)

Slide 110

Slide 110 text

HTTP/1.1 200 OK Content-Type: text/html // loaded from cache
content

Slide 111

Slide 111 text

Flushing critical stuff early

Slide 112

Slide 112 text

Traditional approach

Slide 113

Slide 113 text

Browser Server GET css & js HTTP/1.1 200 OK Content-Type: text/html GET /foo.html </head><body></body></html>

Slide 114

Slide 114 text

HTTP supports streaming

Slide 115

Slide 115 text

Browser Server GET /foo.html HTTP/1.1 200 OK Content-Type: text/html </head> GET css & js

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

Problems

Slide 118

Slide 118 text

Headers are already sent

Slide 119

Slide 119 text

Redirects

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

Proxies, servers, load balancers may buffer content

Slide 122

Slide 122 text

Browsers may wait before starting to render HTML

Slide 123

Slide 123 text

AJAX?

Slide 124

Slide 124 text

JSON/XML

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

Caching what assets are needed

Slide 127

Slide 127 text

GET  /literature.AddPublicationsDialog   HTTP/1.1  200  OK   Content-­‐Type:  application/json   {          "data":  {...},          "css":  ["AddPublicationsDialog.css"],          "js":  ["AddPublicationsDialogView.js"],          "html":  ["addConferencePaperSelection.html"]   }

Slide 128

Slide 128 text

localStorage.setItem(      "literature.AddPublicationsDialog",      {          "css":  ["AddPublicationsDialog.css"],          "js":  ["AddPublicationsDialogView.js"],          "html":  ["addConferencePaperSelection.html"]      }   );

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

Rant

Slide 132

Slide 132 text

Single page apps

Slide 133

Slide 133 text

It takes longer until something is visible

Slide 134

Slide 134 text

Cost of server side rendering

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

Compared with…

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

https://www.flickr.com/photos/91026431@N05/8497636527/

Slide 139

Slide 139 text

Slow connections

Slide 140

Slide 140 text

High latency

Slide 141

Slide 141 text

The internet gets slower and slower

Slide 142

Slide 142 text

It’s hard work to keep a page fast

Slide 143

Slide 143 text

Lots of hacks around HTTP needed

Slide 144

Slide 144 text

It needs to get better

Slide 145

Slide 145 text

SPDY

Slide 146

Slide 146 text

HTTP/2.0

Slide 147

Slide 147 text

For the user it works the same

Slide 148

Slide 148 text

No changes in Headers, Semantics etc

Slide 149

Slide 149 text

GET  /  HTTP/2.0   Host:  www.researchgate.net   HTTP/2.0  200  OK   Content-­‐Type:  text/plain   Content

Slide 150

Slide 150 text

Changes on transport level

Slide 151

Slide 151 text

TLS only

Slide 152

Slide 152 text

Binary instead of textual

Slide 153

Slide 153 text

Header compression

Slide 154

Slide 154 text

Smaller requests and responses

Slide 155

Slide 155 text

Headers are received early (1st packet)

Slide 156

Slide 156 text

Fully multiplexed

Slide 157

Slide 157 text

1 connection for parallelism

Slide 158

Slide 158 text

No domain sharding needed

Slide 159

Slide 159 text

Low overhead for a request

Slide 160

Slide 160 text

No concatenation needed

Slide 161

Slide 161 text

Better cache hit ratio

Slide 162

Slide 162 text

More granular loading

Slide 163

Slide 163 text

Less development overhead

Slide 164

Slide 164 text

No content

Slide 165

Slide 165 text

https://www.flickr.com/photos/ksayer/5614813296/

Slide 166

Slide 166 text

Server push

Slide 167

Slide 167 text

Prioritize critical assets

Slide 168

Slide 168 text

Browser Server Push CSS & JS HTTP/1.1 200 OK Content-Type: text/html </head><body></body></html> GET /foo.html

Slide 169

Slide 169 text

Great

Slide 170

Slide 170 text

When can I use it?

Slide 171

Slide 171 text

Browser support

Slide 172

Slide 172 text

http://caniuse.com/#feat=http2

Slide 173

Slide 173 text

http://caniuse.com/#search=spdy

Slide 174

Slide 174 text

Server support

Slide 175

Slide 175 text

Nginx https://www.nginx.com/blog/early-alpha-patch-http2/

Slide 176

Slide 176 text

https://github.com/icing/mod_h2 Apache httpd

Slide 177

Slide 177 text

Performance best practices will evolve

Slide 178

Slide 178 text

Stay up to date

Slide 179

Slide 179 text

Expect more frequent HTTP protocol iterations

Slide 180

Slide 180 text

http://twitter.com/BastianHofmann http://lanyrd.com/people/BastianHofmann http://speakerdeck.com/u/bastianhofmann [email protected]