Slides by Alberto Varela / @artberri
Find me at github.com/artberri | twiter.com/artberri | berriart.com | [email protected]
Note left of Client: Hey! I wan't to talk, check my ID Client-->Server: SYN Note right of Server: "Look nice! Here's mine!" Server-->Client: SYN+ACK Note left of Client: "Look nice too! Let's talk." Client-->Server: ACK Note left of Client: "This is what I want (Finally!)" Client-->Server: request?
Note over Client, Server: TCP Handshake Client-->Server: ClientHello Server-->Client: ServerHello, Certificate, ServerHelloDone Client-->Server: ClientKeyExchange, ChangeCipherSpec, Finished Server-->Client: ChangeCipherSpec, Finished Client-->Server: ...
Note over Client, Server: TCP Handshake Client-->Server: ClientHello Server-->Client: ServerHello, ChangeCipherSpec, Finished Client-->Server: ChangeCipherSpec, Finished Client-->Server: GET /page
Client->Server: GET /page (with handshakes,...) Server->Client: Some HTML Client->Server: GET /style.css /script.js (new connections) Server->Client: Some CSS and a ton of JS Client->Server: GET /image-x.jpg (more connections) Server->Client: Some images Client->Server: GET /more-images-x.jpg (HOL blocking) Server->Client: Some more images...
This demo consists of an image made with a 224 tiles grid, inspired by Golang's Gophertiles
Client->Server: GET /page (with handshakes,...) Note right of Server: Single connection, single handshake Server->Client: Some HTML Note right of Server: The server can push Server-->Client: PUSH /style.css Server-->Client: PUSH /script.js Client->Server: GET /image-1.jpg /image-2.jpg /image-3.jpg ... Note right of Server: No HoL blocking Server->Client: image1 Server->Client: image2 Server->Client: image3
This demo consists of an image made with a 224 tiles grid, inspired by Golang's Gophertiles
This demo consists of an image made with a 224 tiles grid, inspired by Golang's Gophertiles
Finally...
Server push, which is defined in the HTTP/2 specification, allows a server to pre‑emptively push resources to a remote client, anticipating that the client may soon request those resources.
Simple example using Nginx
server {
# Ensure that HTTP/2 is enabled for the server
listen 443 ssl http2;
ssl_certificate ssl/certificate.pem;
ssl_certificate_key ssl/key.pem;
root /var/www/html;
# whenever a client requests demo.html, also push
# /style.css, /image1.jpg and /image2.jpg
location = /demo.html {
http2_push /style.css;
http2_push /image1.jpg;
http2_push /image2.jpg;
}
}
Simple example using Nginx and the preload header with PHP
server {
# Ensure that HTTP/2 is enabled for the server
listen 443 ssl http2;
ssl_certificate ssl/certificate.pem;
ssl_certificate_key ssl/key.pem;
root /var/www/html;
# Intercept Link header and initiate requested Pushes
location = /myapp {
proxy_pass http://upstream;
http2_push_preload on;
}
}
header("Link: <{$uri}>; rel=preload; as=image", false);
Nginx pushing only on the first visit (using cookies)
server {
listen 443 ssl http2 default_server;
ssl_certificate ssl/certificate.pem;
ssl_certificate_key ssl/key.pem;
root /var/www/html;
http2_push_preload on;
location = /demo.html {
add_header Set-Cookie "session=1";
add_header Link $resources;
}
}
map $http_cookie $resources {
"~*session=1" "";
default "</style.css>; as=style; rel=preload, </image1.jpg>; as=image; rel=preload,
</image2.jpg>; as=style; rel=preload";
}