Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
HTTP/2.0 101 Introduction
Search
Bastian Hofmann
October 03, 2015
Programming
420
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
HTTP/2.0 101 Introduction
Bastian Hofmann
October 03, 2015
More Decks by Bastian Hofmann
See All by Bastian Hofmann
Monitoring in Kubernetes with Prometheus and Grafana
bastianhofmann
0
370
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
150
Highly available cross-region deployments with Kubernetes
bastianhofmann
1
170
From source to Kubernetes in 30 minutes
bastianhofmann
0
200
Introduction to Kubernetes
bastianhofmann
1
140
CI/CD with Kubernetes
bastianhofmann
0
250
Creating a fast Kubernetes Development Workflow
bastianhofmann
1
290
Deploying your first Micro-Service application to Kubernetes
bastianhofmann
2
210
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
280
Other Decks in Programming
See All in Programming
継続モナドとリアクティブプログラミング
yukikurage
3
640
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
210
えっ!!コードを読まずに開発を!?
hananouchi
0
230
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
170
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
350
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
160
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.8k
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.3k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
350
今さら聞けない .NET CLI
htkym
0
110
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.8k
ラッコキーワード サービス紹介資料
rakko
1
4M
WENDY [Excerpt]
tessaabrams
11
38k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
230
AI: The stuff that nobody shows you
jnunemaker
PRO
9
840
Site-Speed That Sticks
csswizardry
13
1.3k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Being A Developer After 40
akosma
91
590k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
Un-Boring Meetings
codingconduct
0
350
WCS-LA-2024
lcolladotor
0
750
Transcript
HTTP/2.0 101 Introduction @BastianHofmann
HTTP/2.0 101 Introduction 101 Switching Protocols @BastianHofmann
https://www.flickr.com/photos/duncan/3171592427/
https://commons.wikimedia.org/wiki/File:Internet1.jpg#/media/File:Internet1.jpg
https://www.flickr.com/photos/neilsingapore/3567378586/
HTTP/0.9 http://www.w3.org/Protocols/HTTP/AsImplemented.html 1991
HTTP/1.0 https://tools.ietf.org/html/rfc1945 1996
HTTP/1.1 http://tools.ietf.org/html/rfc2616 1999
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
https://www.flickr.com/photos/offshore/1433329174/
None
http://www.impressivewebs.com/importance-of-website- performance-sources/
Average page size
Average asset count
http://www.soasta.com/blog/page-bloat-average-web-page-2-mb/
http://httparchive.org/trends.php
The internet gets slower and slower
https://www.flickr.com/photos/91026431@N05/8497636527/
Slow connections
High latency
https://flic.kr/p/KpBcj
It’s hard work to keep a page fast
Lots of hacks around HTTP needed
It needs to get better
SPDY
HTTP/2 http://tools.ietf.org/html/rfc7540 http://tools.ietf.org/html/rfc7541 2015
New possibilities for web applications
Increased performance
Old truths may not be valid anymore
Before we start
A few words about me
None
None
None
None
Questions? Ask
http://speakerdeck.com/u/bastianhofmann
HTTP in detail
The anatomy of a page load
None
Every request one TCP connection
None
User enters URL
DNS lookup
TCP connection
TLS handshake
This already takes time
Optimizations
DNS caching
Connection Keep Alive
TLS optimizations
https://istlsfastyet.com/
None
Finally: HTTP
GET / HTTP/1.1 Host: www.researchgate.net HTTP/1.1 200 OK Content-Type: text/plain
Content
HTTP request
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: …
https://www.flickr.com/photos/40987321@N02/5580348753/
HTTP response
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
HTTP/2
For the user it works the same
No changes in Headers, Semantics etc
GET / HTTP/2.0 Host: www.researchgate.net HTTP/2.0 200 OK Content-Type: text/plain
Content
Changes on transport level
TLS only
Binary instead of textual
Header compression
Smaller requests and responses
Less roundtrips
Headers are received early (1st packet)
Response body
HTML response
DOM parsing
Rendering
Asset fetching
Applying CSS
Executing JS
https://www.flickr.com/photos/hangdog/10991275/
Blocking HTML rendering
CSS
JS
CSS triggers repaints
JS can manipulate the DOM
JS can access attributes set by CSS
HTTP/1.1 200 OK Content-Type: text/html <html> <head> <link href="main.css" >
<link href="profile.css" > <script src="library.js" /> <script src="app.js" /> <script> // some JS </script> </head> <body>
<script src="demo_async.js" async></script>
Every request one TCP connection
Concurrent connection limits
Network congestion
http://www.browserscope.org/?category=network
Domain sharding
http://c5.rgstatic.net/profile.css http://c4.rgstatic.net/icon.png
Shards should be persistent
Additional handshakes and connections
Network congestion
TCP Slow Start
https://de.wikipedia.org/wiki/Transmission_Control_Protocol#/media/File:TCPSlowStartundCongestionAvoidance.svg
Ideal number of shards
https://codeascraft.com/2014/02/19/reducing-domain- sharding/
Page sizes
Less content
GZIP
Image compression
Minification
JS
CSS
HTML
Debugging problems
None
Sourcemaps
Less requests
Concatenation
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
https://c5.rgstatic.net/c/a9b943a25d126865806885d2fd94b5f9/mainbundle.js
Spritemaps
None
How to bundle
Over fetching
90% CSS unused
Cache invalidation
HTTP/2
Only 1 connection
Fully multiplexed
No domain sharding needed
Low overhead for a request
No concatenation needed
Better cache hit ratio
More granular loading
Less development overhead
None
https://www.flickr.com/photos/ksayer/5614813296/
Critical rendering path
None
None
What is visible?
What is critical?
Inline critical assets
Either inline always
Caching?
First request
HTTP/1.1 200 OK Content-Type: text/html <html> <head> <styles> … your
critical css </styles> </head> <body> <div>content</div> load main.css async set cookie that other css was loaded </body> </html>
Subsequent request (if Cookie set)
HTTP/1.1 200 OK Content-Type: text/html <html> <head> <link href="main.css" >
// loaded from cache </head> <body> <div>content</div> </body> </html>
Flushing critical stuff early
Traditional approach
Browser Server GET css & js HTTP/1.1 200 OK Content-Type:
text/html <html> <head><link ..><script ..> GET /foo.html </head><body></body></html>
HTTP supports streaming
Browser Server GET /foo.html <body></body> </html> HTTP/1.1 200 OK Content-Type:
text/html <html> <head><link ..><script ..></head> GET css & js
None
https://developer.mozilla.org/en-US/docs/Web/HTTP/ Controlling_DNS_prefetching
https://developer.mozilla.org/en-US/docs/Web/HTTP/ Link_prefetching_FAQ
Problems
Headers are already sent
Redirects
None
Proxies, servers, load balancers may buffer content
Browsers may wait before starting to render HTML
AJAX?
JSON/XML
None
Caching what assets are needed
GET /literature.AddPublicationsDialog HTTP/1.1 200 OK Content-Type: application/json { "data": {...},
"css": ["AddPublicationsDialog.css"], "js": ["AddPublicationsDialogView.js"], "html": ["addConferencePaperSelection.html"] }
localStorage.setItem( "literature.AddPublicationsDialog", { "css": ["AddPublicationsDialog.css"], "js": ["AddPublicationsDialogView.js"], "html": ["addConferencePaperSelection.html"] }
);
None
None
HTTP/2
Server push
Prioritize critical assets
Browser Server Push CSS & JS HTTP/1.1 200 OK Content-Type:
text/html <html> <head><link ..><script ..> </head><body></body></html> GET /foo.html
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! <script src=„/main.js"></script>' ); }).listen(443); https://www.igvita.com/2013/06/12/innovating-with-http-2.0-server-push/
Headers X-Associated-Content
Automated learning
Great
When can I use it?
Browser support
http://caniuse.com/#feat=http2
http://caniuse.com/#search=spdy
Server support
Nginx http://nginx.org/en/docs/http/ngx_http_v2_module.html
https://github.com/icing/mod_h2 Apache httpd
Performance best practices will evolve
Stay up to date
Expect more frequent HTTP protocol iterations
https://joind.in/15435
http://twitter.com/BastianHofmann http://lanyrd.com/people/BastianHofmann http://speakerdeck.com/u/bastianhofmann
[email protected]