How it works...
First, note that the HTTP/2 requires the secured connection. The server push is very simple to implement. Since Go 1.8, the HTTP package provides the Pusher interface, which could be used to Push the assets before they are required. If the client, usually browser, supports the HTTP/2 protocol and the handshake with the server is successful, the ResponseWriter in Handler or HandlerFunc could be cast to Pusher. The Pusher provides only the Push method. The Push method consumes the target (which could be the absolute path or absolute URL) to resource and PushOptions, which can provide the additional options (by default the nil could be used).
In the preceding example, look at the output of the developer's tool in the browser. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access