1 of 30

HTTP/2 Push for the Stars

Tom J Nowell

2 of 30

Old Couches

3 of 30

4 of 30

HTTP 400 Bad Request

5 of 30

Order new couch

Construct couch from materials

Deliver couch

Install Couch on delivery

6 of 30

New Couch

7 of 30

Insert picture of new couch

8 of 30

Order new couch

Construct couch from materials

Deliver couch

Install Couch on delivery

9 of 30

Order new couch

Construct couch from materials

Deliver couch

Install Couch on delivery

Request URL

Run WordPress to get the result

Send result over network

Render page on delivery

10 of 30

Backend performance

Request URL

Run WordPress to get the result

Send result over network

Render page on delivery

11 of 30

Great Ways to Ruin Time To First Byte

Autoptimize

Really Simple SSL

Anything that output buffers the whole page

12 of 30

Frontend performance

Request URL

Run WordPress to get the result

Send result over network

Render page on delivery

13 of 30

Networking performance

Request URL

Run WordPress to get the result

Send result over network

Render page on delivery

14 of 30

The Waterfall

15 of 30

HTTP 1.1 Waterfall

16 of 30

HTTP/2

17 of 30

Preloading Assets With Link Tags

<link rel="prefetch"� href="/wp-content/themes/test/style.css" as="style"/>

<link rel="prefetch"� href="https://www.googletagmanager.com/gtag/js?id=1234" />

<link rel="prefetch"� href="https://example.com/image.png" />

<link rel="next"� href="/page2">

18 of 30

Preloading with HTTP headers

Link: https://example.com/other/styles.css; rel=preload; as=style

Link: https://example.com/logo.png; rel=preload; as=image

Link: https://www.googletagmanager.com/gtag/js?id=1234; rel=preload; as=script

<?php�header( 'Link: https://example.com/main.js; rel=preload; as=script' );

19 of 30

Preloading Fonts with HTTP headers

Link: <font.woff2>;rel="preload";as="font";crossorigin

20 of 30

HTTP/2 Push

21 of 30

Pushing with Nginx

server {� listen 443 ssl http2;�...� location = / {� http2_push /wp-content/themes/test/style.css;� }�}

22 of 30

Testing HTTP/2 Push

  1. Browser dev tools�In chrome, under the network tab, initiator: Push / Other
  2. Terminal Command:�nghttp -ans https://tomjn.com

23 of 30

Testing HTTP/2 Push

nghttp -ans https://tomjn.com��id responseEnd requestStart process code size request path� 13 +21.71ms +355us 21.36ms 200 3K /� 2 +50.03ms * +20.87ms 29.16ms 200 33K /wp-includes/js/jquery/jquery.js?ver=1.12.4� 4 +54.01ms * +20.93ms 33.09ms 200 3K /wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1� 6 +54.18ms * +20.94ms 33.24ms 200 3K /wp-content/uploads/2016/11/favicon.png� 8 +55.41ms * +20.95ms 34.46ms 200 4K /wp-includes/js/wp-emoji-release.min.js?ver=5.1.1� 10 +55.47ms * +20.98ms 34.49ms 200 753 /wp-includes/js/wp-embed.min.js?ver=5.1.1� 12 +55.53ms * +20.98ms 34.55ms 200 639 /wp-content/plugins/jetpack/_inc/build/widgets/milestone/milestone.min.js?ver=20160520� 14 +55.86ms * +21.01ms 34.85ms 200 4K/wp-includes/css/dist/block-library/style.min.css?ver=5.1.1� 16 +67.34ms * +21.01ms 46.33ms 200 14K /wp-content/themes/tomjn/style.css?ver=5� 18 +71.42ms * +21.03ms 50.40ms 200 27K /wp-includes/css/dashicons.min.css?ver=5.1.1�

24 of 30

Auto-pushing from PHP with Nginx

server {� listen 443 ssl http2;�...� # Intercept Link header and initiate requested Pushes� location = /myapp {� proxy_pass http://upstream;� http2_push_preload on;� }�}

25 of 30

Auto-Pushed:

Link: </style.css>; as=style; rel=preload

Not Auto-Pushed:

Link: <http://3rdparty.com/style.css>; as=style; rel=preload

Link: </style.css>; as=style; rel=preload; nopush

26 of 30

Pushing via functions.php

function tomjnscripts() {� // hint to the browser to request a few extra things via http2� header("Link: <".get_stylesheet_uri()."?ver=5>; rel=preload; as=style", false);� header("Link: </wp-content/plugins/gutenberg/blocks/build/style.css>; rel=preload; as=style", false);� header("Link: </wp-includes/js/jquery/jquery.js?ver=1.12.4>; rel=preload; as=script", false);� header("Link: </wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1>; rel=preload; as=script", false);� header("Link: <https://use.typekit.net/wtc2mfi.js>; rel=preload; as=script", false);� header("Link: <https://www.googletagmanager.com/gtag/js?id=UA-6510359-3>; rel=preload; as=script", false);� // etc....�}�add_action( 'wp_enqueue_scripts', 'tomjnscripts' );

27 of 30

I’m Tom J Nowell

28 of 30

Bored of your job? We have a fix for that�https://vip.wordpress.com/careers

29 of 30

https://tomjn.com�@tarendai

30 of 30

https://tomjn.com�@tarendai

?