Sunday, 5 March 2017

Configuring HTTP2 Push with WordPress

Server Push allows you to push a set of files down to the browser along with the request for the HTML even before the HTML is parsed. This means sending things like logos and CSS before the browser knows to request them, and thus speeding up the perceived load time of your page. Let’s say that you had a site that runs on PHP, which of course your WordPress instance does, and you wanted to use HTTP2 Server Push to push down two CSS files and your logo.
You can use the following code which will do just that for you…
header("Link: </css/vendor.css>; rel=preload; as=style", false);
header("Link: </css/styles.css>; rel=preload; as=style", false);
header("Link: </images/site/logo–red.svg>; rel=preload; as=image", false);
This has to be at the very very top of the page being requested, so if you’re working with WordPress then you’re going to want to put it into your themes header.php file. The URL of the asset you want needs to go within the brackets and you need to define the type of file you’re pushing as well.
The last argument, false, comes from a PHP header replace function part of the


No comments:

Post a Comment