Andrew Betts
Principal developer advocate | Fastly
The power of the network Andrew Betts Principal developer advocate - - PowerPoint PPT Presentation
The power of the network Andrew Betts Principal developer advocate | Fastly Who is this guy? Developer relations at Fastly W3C Technical Architecture Group Previously Financial Times, Nikkei Agenda today Why you should
Andrew Betts
Principal developer advocate | Fastly
webpagetest.org
Complexity of resource loading is increasing Better browser support gives developers more control, better tools (like webpagetest) offer better monitoring.
HTTP Archive, April 2017
https://mobiforge.com/research-analysis/the-web-is-doom
http://www.pcworld.com/article/3060622
https://whatdoesmysitecost.com/ (tested MSNBC.com, 3.35MB in June 2017)
Proliferation of third party tools on the page Ghostery regularly finds more than 50 third party scripts included on a single web page.
Geneva, Switzerland
“High performance browser networking”, Ilya Grigorik (O’Reilly 2013)
Application Presentation Session Transport Network Data link Physical HTTP TCP IP Ethernet / Wi-fi / 3G / Bluetooth Mostly makes sense Total voodoo
(yes, technically there was also a 0.9)
andrew in ~$ host google.com google.com has address 216.58.195.78 andrew in ~$ telnet 216.58.195.78 80 Connected to sfo07s16-in-f14.1e100.net. GET /about/ HTTP/1.0 200 OK Content-Type: text/html <html class=”google” lang=”en”> <head> <title>About Us | Google</title> … andrew in ~$
Hey DNS, where’s Google.com?
Browser
Try 216.58.195.78
DNS
Hey 216.58.195.78, can we talk?
Browser
Sure, go ahead
GET /about/
Browser
Here you go. And we’re done. Bye!
Hang on, this page has images on it. Can we talk again?
Browser
Sure, go ahead
GET /images/logo.png
Browser
Here you go. And we’re done. Bye!
andrew in ~$ host example.com example.com has address 93.184.216.34 andrew in ~$ telnet 93.184.216.34 80 Connected to 93.184.216.34. GET / HTTP/1.1 Host: example.com HTTP/1.1 200 OK Cache-Control: max-age=604800 Content-Type: text/html Date: Wed, 10 May 2017 19:41:51 GMT Vary: Accept-Encoding Content-Length: 1270 <html> <head> <title>Example Domain</title> ...
Hey DNS, where’s example.com?
Browser
Try 93.184.216.34
DNS
Hey 93.184.216.34, can we talk?
Browser
Sure, go ahead
IANA
GET /about/ from example.com
Browser
Here you go, and hey, I’ll stick around for a while
IANA
GET /images/logo.png from example.com
Browser
Here you go, and hey, I’ll stick around for a while
IANA
You haven’t said anything for a while, so I’m going to hang up
IANA
andrew in ~$ openssl s_client -connect 93.184.216.34:443 CONNECTED(00000003) depth=1 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert New, TLSv1/SSLv3, Cipher is AES256-SHA
Host: example.com HTTP/1.1 200 OK Cache-Control: max-age=604800 Content-Type: text/html Date: Wed, 10 May 2017 20:54:23 GMT Vary: Accept-Encoding Content-Length: 1270 <html> <head> <title>Example Domain</title> ... www.bearfruit.org/2008/04/17/telnet-for-testing-ssl-https-websites/
Hey DNS, where’s example.com?
Browser
Try 93.184.216.34
DNS
Hey 93.184.216.34, can we talk?
Browser
Sure, go ahead
IANA
Great, can we upgrade to TLS?
Browser
OK, this is my certificate
IANA
Here’s my key and we’ll use cipher A
Browser
Cipher A, got it
IANA
Here you go, and hey, I’ll stick around for a while
IANA
GET /about/ from example.com
Browser
Here you go, and hey, I’ll stick around for a while
IANA
GET /images/logo.png from example.com
Browser
“High performance browser networking”, Ilya Grigorik (O’Reilly 2013)
andrew in ~$ curl --http2 -v https://example.com/ * Trying 93.184.216.34... * Connected to example.com (93.184.216.34) port 443 (#0) * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) > GET / HTTP/2 > Host: example.com > < HTTP/2 200 < cache-control: max-age=604800 < content-type: text/html < date: Wed, 10 May 2017 20:54:23 GMT < vary: Accept-Encoding < content-length: 1270 < <html> <head> ... simonecarletti.com/blog/2016/01/http2-curl-macosx/
Hey DNS, where’s example.com?
Browser
Try 93.184.216.34
DNS
Hey 93.184.216.34, can we talk?
Browser
Sure, go ahead
IANA
Great, can we upgrade to TLS?
Browser
OK, this is my certificate
IANA
Here’s my key and we’ll use cipher A
Browser
Cipher A, got it
IANA
OK, here’s api/prices and a bit more of video.mp4
IANA
GET /about/ from example.com
Browser
Here’s /about/, hey also here’s logo.png and the first part of video.mp4
IANA
GET /api/prices. Also, POST /api/login.
Browser
Req1 Pkt 1 Req2 Pkt 1 Req1 Pkt 1 Req2 Pkt 2 Req2 Pkt 3 Push Pkt 1 Req4 Pkt 1 Req3 Pkt 1 Req3 Pkt 2
Denver user Edge (Denver) Server (Stockholm) Higher probability of existing connection
Denver user Edge 1 (Denver) Edge 2 (Europe) Always on, optimised, low latency connection Server (Stockholm)
Connections remain expensive to set up. Use a routing layer to expose only one origin.
example.com In-house app Video provider Analytics provider
Cold start, short distance Always-on, long distance
An offline-capable news reading progressive web app with cache insights
Static: Stuff that never changes JavaScript CSS Images Templates
/resources/style-v3.css
Dynamic: unique to a single user Inbox message list Shopping cart Preference values
/my/cart
Years private*
* Still benefits from DSA
Event driven: changes when things happen Articles Product lists Search results Stock prices
/api/getCurrentPrice
Years*
* If you can purge
Browser HTTP cache Fastly Origin server
jakearchibald.com/2016/caching-best-practices/
Version 1, cached
Version 2, live
Version 1, cached Maybe bang? + + =
jakearchibald.com/2016/caching-best-practices/
User Event: Comment posted Edge Server
Uncached, fetch from origin Hit! return “304 Not Modified” from Edge cache After purge, uncached again
PURGE
MISS...
Users max-age expires Edge Server
Many requests per second are flooding the edge servers Just one request goes to origin. The rest are held at the edge. All requests fulfilled Subsequent requests served from fresh cache After expiry, requests still get fast cached response Asynchronous fetch to refresh the cache Cache repopulated
Users max-age expires Edge Server
Requests flooding in Just one request goes to origin, populates cache at the edge Request after expiry causes fetch to origin Origin server is
connection
stale-while-reval expires
SERVER DOWN! Server super-stale
<esi:include src="http://example.com/1.html" alt="http://bak.example.com/2.html" onerror="continue"/>
index.html my-news.html Cache-control: max-age=86400 Cache-control: private
Origin server Edge cache / CDN Browser
/frags/header /home.frag
Server
/frags/footer / https://developers.google.com/web/updates/2016/06/sw-readablestreams
Browser
Link: </resources/js/app.js>;rel=preload;as=script
Browser HTTP cache CDN Origin server
Browser tab CDN Origin server Preload cache HTTP cache HTTP/2 push cache
Per page Per connection
https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/
User Edge Server
Get page.html Browser sees Link preload header and fetches app.js Browser encounters <script> tag, fetches app.js again
Preload cache Push cache
Server includes Link: preload header for app.js CDN pushes app.js along with response to page.html. JS goes into the push cache. app.js is pulled from push cache into the preload cache Preload cache wiped when user goes to another page
Link: </resources/js/app.js>;rel=preload;as=script
PRELOADED, MAY BE PUSHED
Link: </resources/js/app.js>;rel=preload;as=script;nopush
PRELOADED, NOT PUSHED
Link: </resources/js/app.js>;rel=preload;as=script;x-http2-push-only
EITHER PRELOADED OR PUSHED BUT NOT BOTH (FASTLY ONLY)
COMING SOON
Browser tab CDN Origin server Preload cache HTTP cache HTTP/2 push cache
Per page Per connection
https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/
Browser tab Image cache Fastly Origin server Preload cache Service worker HTTP cache HTTP/2 push cache
Per page Per origin (domain) Per connection
https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/
User Event: Comment posted Fastly Server
Uncached, fetch from origin
PURGE SILENT WEB PUSH
COMING SOON
Clear-Site-Data: "cache", "cookies", "storage", "executionContexts"
COMING SOONISH
Content-Security-Policy: HTTP-Strict-Transport-Security: X-Frame-Options: Referrer-Policy: Cache-Control: X-XSS-Protection: ... Content-Security-Policy: HTTP-Strict-Transport-Security: X-Frame-Options: Referrer-Policy: Cache-Control: X-XSS-Protection: ... Content-Security-Policy: HTTP-Strict-Transport-Security: X-Frame-Options: Referrer-Policy: Cache-Control: X-XSS-Protection: ...
/home /about /shop
https://wicg.github.io/origin-policy/
COMING SOON
Feature-Policy: { "geolocation": [ "self", "https://example.com" ], “vibrate”: [] }