Slide 1

Slide 1 text

HTTP/2.0 101 Introduction @BastianHofmann

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

Questions? Ask

Slide 6

Slide 6 text

http://speakerdeck.com/u/bastianhofmann

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 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 14

Slide 14 text

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

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Average page size

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Average asset count

Slide 20

Slide 20 text

http://httparchive.org/trends.php

Slide 21

Slide 21 text

The internet gets slower and slower

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Slow connections

Slide 24

Slide 24 text

High latency

Slide 25

Slide 25 text

https://flic.kr/p/KpBcj

Slide 26

Slide 26 text

It’s hard work to keep a page fast

Slide 27

Slide 27 text

Lots of hacks around HTTP needed

Slide 28

Slide 28 text

It needs to get better

Slide 29

Slide 29 text

SPDY

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

New possibilities for web applications

Slide 32

Slide 32 text

Increased performance

Slide 33

Slide 33 text

Old truths may not be valid anymore

Slide 34

Slide 34 text

HTTP/1.1 in detail

Slide 35

Slide 35 text

User enters URL

Slide 36

Slide 36 text

DNS lookup

Slide 37

Slide 37 text

TCP connection

Slide 38

Slide 38 text

TLS handshake

Slide 39

Slide 39 text

This already takes time

Slide 40

Slide 40 text

Finally: HTTP

Slide 41

Slide 41 text

HTTP request

Slide 42

Slide 42 text

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

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 Content-Type: text/plain Content

Slide 47

Slide 47 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 48

Slide 48 text

HTTP/2

Slide 49

Slide 49 text

For the user it works the same

Slide 50

Slide 50 text

No changes in Headers, Semantics etc

Slide 51

Slide 51 text

Almost no changes in Headers, Semantics etc

Slide 52

Slide 52 text

Protocol (h2) is established during TLS handshake

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Changes on transport level

Slide 55

Slide 55 text

TLS only

Slide 56

Slide 56 text

Binary instead of textual

Slide 57

Slide 57 text

Multiple requests are multiplexed over one TCP connection

Slide 58

Slide 58 text

Server Push

Slide 59

Slide 59 text

Header compression

Slide 60

Slide 60 text

Smaller requests and responses

Slide 61

Slide 61 text

Less roundtrips

Slide 62

Slide 62 text

Headers are received early (1st packet)

Slide 63

Slide 63 text

HTTP Response body

Slide 64

Slide 64 text

HTML response

Slide 65

Slide 65 text

DOM parsing

Slide 66

Slide 66 text

Rendering

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Asset fetching

Slide 69

Slide 69 text

Applying CSS

Slide 70

Slide 70 text

Executing JS

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

Blocking HTML rendering

Slide 73

Slide 73 text

CSS

Slide 74

Slide 74 text

JS

Slide 75

Slide 75 text

CSS triggers repaints

Slide 76

Slide 76 text

JS can manipulate the DOM

Slide 77

Slide 77 text

JS can access attributes set by CSS

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

Slide 80

Slide 80 text

Lots of assets

Slide 81

Slide 81 text

HTTP/1.1

Slide 82

Slide 82 text

Every request one TCP connection

Slide 83

Slide 83 text

Connection Keep Alive

Slide 84

Slide 84 text

Every request blocks one TCP connection

Slide 85

Slide 85 text

Network congestion

Slide 86

Slide 86 text

Concurrent connection limits

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

Domain sharding

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

Shards should be persistent

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

Additional handshakes and connections

Slide 93

Slide 93 text

Network congestion

Slide 94

Slide 94 text

TCP Slow Start

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

Ideal number of shards

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

Page sizes

Slide 99

Slide 99 text

Less content

Slide 100

Slide 100 text

GZIP

Slide 101

Slide 101 text

Image compression

Slide 102

Slide 102 text

Minification

Slide 103

Slide 103 text

JS

Slide 104

Slide 104 text

CSS

Slide 105

Slide 105 text

HTML

Slide 106

Slide 106 text

Debugging problems

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

Sourcemaps

Slide 109

Slide 109 text

=> More requests

Slide 110

Slide 110 text

Less requests

Slide 111

Slide 111 text

Concatenation

Slide 112

Slide 112 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 113

Slide 113 text

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

Slide 114

Slide 114 text

Spritemaps

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

How to bundle

Slide 117

Slide 117 text

Over fetching

Slide 118

Slide 118 text

90% CSS unused

Slide 119

Slide 119 text

Cache invalidation

Slide 120

Slide 120 text

Under fetching

Slide 121

Slide 121 text

HTTP/2

Slide 122

Slide 122 text

Only 1 connection

Slide 123

Slide 123 text

Fully multiplexed

Slide 124

Slide 124 text

No domain sharding needed

Slide 125

Slide 125 text

Low overhead for a request

Slide 126

Slide 126 text

No concatenation needed

Slide 127

Slide 127 text

Better cache hit ratio

Slide 128

Slide 128 text

More granular loading

Slide 129

Slide 129 text

Less development overhead

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

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

Slide 132

Slide 132 text

Critical rendering path

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

What is visible?

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

What is critical?

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

HTTP/1.1

Slide 139

Slide 139 text

Inline critical assets

Slide 140

Slide 140 text

Either inline always

Slide 141

Slide 141 text

Caching?

Slide 142

Slide 142 text

First request

Slide 143

Slide 143 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 144

Slide 144 text

Subsequent request (if Cookie set)

Slide 145

Slide 145 text

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

Slide 146

Slide 146 text

Flushing critical stuff early

Slide 147

Slide 147 text

Traditional approach

Slide 148

Slide 148 text

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

Slide 149

Slide 149 text

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

Slide 150

Slide 150 text

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

Slide 151

Slide 151 text

HTTP supports streaming

Slide 152

Slide 152 text

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

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

Problems

Slide 155

Slide 155 text

Headers are already sent

Slide 156

Slide 156 text

Redirects

Slide 157

Slide 157 text

window.location = "...";

Slide 158

Slide 158 text

No content

Slide 159

Slide 159 text

Proxies, servers, load balancers may buffer content

Slide 160

Slide 160 text

Browsers may wait before starting to render HTML

Slide 161

Slide 161 text

AJAX?

Slide 162

Slide 162 text

JSON

Slide 163

Slide 163 text

No content

Slide 164

Slide 164 text

Caching what assets are needed

Slide 165

Slide 165 text

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

Slide 166

Slide 166 text

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

Slide 167

Slide 167 text

No content

Slide 168

Slide 168 text

No content

Slide 169

Slide 169 text

HTTP/2

Slide 170

Slide 170 text

Server push

Slide 171

Slide 171 text

Prioritize critical assets

Slide 172

Slide 172 text

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

Slide 173

Slide 173 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 174

Slide 174 text

Headers X-Associated-Content

Slide 175

Slide 175 text

Automated learning

Slide 176

Slide 176 text

Great

Slide 177

Slide 177 text

When can I use it?

Slide 178

Slide 178 text

Browser support

Slide 179

Slide 179 text

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

Slide 180

Slide 180 text

Server support

Slide 181

Slide 181 text

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

Slide 182

Slide 182 text

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

Slide 183

Slide 183 text

Who is using it already?

Slide 184

Slide 184 text

chrome://net-internals/#http2

Slide 185

Slide 185 text

Performance best practices will evolve

Slide 186

Slide 186 text

Monitor and test

Slide 187

Slide 187 text

Expect more frequent HTTP protocol iterations

Slide 188

Slide 188 text

Stay up to date

Slide 189

Slide 189 text

https://joind.in/talk/856a8

Slide 190

Slide 190 text

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