Slide 1

Slide 1 text

HTTP/2.0 101 Introduction @BastianHofmann

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 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 9

Slide 9 text

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

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Average page size

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Average asset count

Slide 15

Slide 15 text

http://httparchive.org/trends.php

Slide 16

Slide 16 text

The internet gets slower and slower

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Slow connections

Slide 19

Slide 19 text

High latency

Slide 20

Slide 20 text

https://flic.kr/p/KpBcj

Slide 21

Slide 21 text

It’s hard work to keep a page fast

Slide 22

Slide 22 text

Lots of hacks around HTTP needed

Slide 23

Slide 23 text

It needs to get better

Slide 24

Slide 24 text

SPDY

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

New possibilities for web applications

Slide 27

Slide 27 text

Increased performance

Slide 28

Slide 28 text

Old truths may not be valid anymore

Slide 29

Slide 29 text

HTTP/1.1 in detail

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

Finally: HTTP

Slide 36

Slide 36 text

HTTP request

Slide 37

Slide 37 text

GET / HTTP/1.1 Host: www.researchgate.net

Slide 38

Slide 38 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 39

Slide 39 text

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

Slide 40

Slide 40 text

HTTP response

Slide 41

Slide 41 text

HTTP/1.1 200 OK Content-Type: text/plain Content

Slide 42

Slide 42 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 43

Slide 43 text

HTTP/2

Slide 44

Slide 44 text

For the user it works the same

Slide 45

Slide 45 text

No changes in Headers, Semantics etc

Slide 46

Slide 46 text

Almost no changes in Headers, Semantics etc

Slide 47

Slide 47 text

Protocol (h2) is established during TLS handshake

Slide 48

Slide 48 text

:authority: www.researchgate.net :method: GET :path: / :scheme: https :status: 200 Content-Type: text/plain Content

Slide 49

Slide 49 text

Changes on transport level

Slide 50

Slide 50 text

TLS only

Slide 51

Slide 51 text

Binary instead of textual

Slide 52

Slide 52 text

Multiple requests are multiplexed over one TCP connection

Slide 53

Slide 53 text

Server Push

Slide 54

Slide 54 text

Header compression

Slide 55

Slide 55 text

Smaller requests and responses

Slide 56

Slide 56 text

Less roundtrips

Slide 57

Slide 57 text

Headers are received early (1st packet)

Slide 58

Slide 58 text

HTTP Response body

Slide 59

Slide 59 text

HTML response

Slide 60

Slide 60 text

DOM parsing

Slide 61

Slide 61 text

Rendering

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Asset fetching

Slide 64

Slide 64 text

Applying CSS

Slide 65

Slide 65 text

Executing JS

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

Blocking HTML rendering

Slide 68

Slide 68 text

CSS

Slide 69

Slide 69 text

JS

Slide 70

Slide 70 text

CSS triggers repaints

Slide 71

Slide 71 text

JS can manipulate the DOM

Slide 72

Slide 72 text

JS can access attributes set by CSS

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

Slide 75

Slide 75 text

Lots of assets

Slide 76

Slide 76 text

HTTP/1.1

Slide 77

Slide 77 text

Every request one TCP connection

Slide 78

Slide 78 text

Connection Keep Alive

Slide 79

Slide 79 text

Every request blocks one TCP connection

Slide 80

Slide 80 text

Network congestion

Slide 81

Slide 81 text

Concurrent connection limits

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

Domain sharding

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

Shards should be persistent

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

Additional handshakes and connections

Slide 88

Slide 88 text

Network congestion

Slide 89

Slide 89 text

TCP Slow Start

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

Ideal number of shards

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

Page sizes

Slide 94

Slide 94 text

Less content

Slide 95

Slide 95 text

GZIP

Slide 96

Slide 96 text

Image compression

Slide 97

Slide 97 text

Minification

Slide 98

Slide 98 text

JS

Slide 99

Slide 99 text

CSS

Slide 100

Slide 100 text

HTML

Slide 101

Slide 101 text

Debugging problems

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Sourcemaps

Slide 104

Slide 104 text

=> More requests

Slide 105

Slide 105 text

Less requests

Slide 106

Slide 106 text

Concatenation

Slide 107

Slide 107 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 108

Slide 108 text

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

Slide 109

Slide 109 text

Spritemaps

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

How to bundle

Slide 112

Slide 112 text

Over fetching

Slide 113

Slide 113 text

90% CSS unused

Slide 114

Slide 114 text

Under fetching

Slide 115

Slide 115 text

Cache invalidation

Slide 116

Slide 116 text

HTTP/2

Slide 117

Slide 117 text

Only 1 connection

Slide 118

Slide 118 text

Fully multiplexed

Slide 119

Slide 119 text

No domain sharding needed

Slide 120

Slide 120 text

Low overhead for a request

Slide 121

Slide 121 text

No concatenation needed

Slide 122

Slide 122 text

Better cache hit ratio

Slide 123

Slide 123 text

More granular loading

Slide 124

Slide 124 text

Less development overhead

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

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

Slide 127

Slide 127 text

Critical rendering path

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

What is visible?

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

What is critical?

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

HTTP/1.1

Slide 134

Slide 134 text

Inline critical assets

Slide 135

Slide 135 text

Either inline always

Slide 136

Slide 136 text

Caching?

Slide 137

Slide 137 text

First request

Slide 138

Slide 138 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 139

Slide 139 text

Subsequent request (if Cookie set)

Slide 140

Slide 140 text

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

Slide 141

Slide 141 text

Flushing critical stuff early

Slide 142

Slide 142 text

Traditional approach

Slide 143

Slide 143 text

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

Slide 144

Slide 144 text

https://developer.mozilla.org/en-US/docs/Web/HTTP/ Controlling_DNS_prefetching

Slide 145

Slide 145 text

https://developer.mozilla.org/en-US/docs/Web/HTTP/ Link_prefetching_FAQ

Slide 146

Slide 146 text

HTTP supports streaming

Slide 147

Slide 147 text

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

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

Problems

Slide 150

Slide 150 text

Headers are already sent

Slide 151

Slide 151 text

Redirects

Slide 152

Slide 152 text

window.location = "...";

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

Proxies, servers, load balancers may buffer content

Slide 155

Slide 155 text

Browsers may wait before starting to render HTML

Slide 156

Slide 156 text

AJAX?

Slide 157

Slide 157 text

JSON

Slide 158

Slide 158 text

No content

Slide 159

Slide 159 text

Caching what assets are needed

Slide 160

Slide 160 text

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

Slide 161

Slide 161 text

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

Slide 162

Slide 162 text

No content

Slide 163

Slide 163 text

No content

Slide 164

Slide 164 text

HTTP/2

Slide 165

Slide 165 text

Server push

Slide 166

Slide 166 text

Prioritize critical assets

Slide 167

Slide 167 text

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

Slide 168

Slide 168 text

spdy.createServer(options, function(req, res) { // push JavaScript asset (/main.js) to the client res.push( '/main.js', {'content-type': ‚application/javascript'}, function(err, stream) { stream.end('alert("hello from push stream!")'); } ); // write main response body and terminate stream res.end( 'Hello World! ' ); }).listen(443); https://www.igvita.com/2013/06/12/innovating-with-http-2.0-server-push/

Slide 169

Slide 169 text

Headers X-Associated-Content

Slide 170

Slide 170 text

Automated learning

Slide 171

Slide 171 text

Great

Slide 172

Slide 172 text

When can I use it?

Slide 173

Slide 173 text

Browser support

Slide 174

Slide 174 text

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

Slide 175

Slide 175 text

Server support

Slide 176

Slide 176 text

Nginx https://www.nginx.com/blog/nginx-1-9-5/

Slide 177

Slide 177 text

https://httpd.apache.org/docs/2.4/mod/mod_http2.html Apache httpd

Slide 178

Slide 178 text

Who is using it already?

Slide 179

Slide 179 text

chrome://net-internals/#http2

Slide 180

Slide 180 text

Performance best practices will evolve

Slide 181

Slide 181 text

Monitor and test

Slide 182

Slide 182 text

Expect more frequent HTTP protocol iterations

Slide 183

Slide 183 text

Stay up to date

Slide 184

Slide 184 text

https://joind.in/talk/13140

Slide 185

Slide 185 text

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