In accordance with the apache documentation, you can control the requests PUSH through the response header Link
. That is, if you will respond your client with an HTML file that depends on a CSS file and another JS, you can send them to the client via PUSH before the same need to order them.
You can do this directly in your server configuration, for each route
<Location /xxx.html>
Header add Link "</xxx.css>;rel=preload"
Header add Link "</xxx.js>;rel=preload"
</Location>
Or simply add the headers to the answer. With PHP you are able to do this through the function header
:
<?php
header("Link </xxx.css>;rel=preload, </xxx.js>; rel=preload");
So when the client loads your HTML page you will also receive the CSS and JS files.
For the first access, which creates the connection to the server, simply inform the HTTP version during the request:
GET / HTTP/2
Host: localhost
The browser, which has HTTP/2 support, will already do this on its own. You can check this in the developer tools in your browser. Here, accessing a page on a server with HTTP/2 support, which sends via PUSH the CSS file, was:
The value h1
in Protocol
indicates HTTP/2 and for the CSS file, second from the list, it is possible to see Push
as Iniciator
of the requisition.
It doesn’t matter if the server has support and the client doesn’t. The logs you analyzed were requests made by a client that supports HTTP2?
– Costamilam
@Costamilam I can’t say. Actually the question is just that. Being enabled on the server, it only depends on a browser behavior (which is not yet default), or can I set something that forces the browser to use HTTP/2? Is there any
header
, ormeta
that I need to add in PHP or HTML?– gustavox