HTTP/2 Push
Content-Type: *
Server push lets the server preemptively "push" website assets to the client without the user having explicitly asked for them. When used with care, we can send what we know the user is going to need for the page they’re requesting.
The target must either be an absolute path (like "/path") or an absolute URL that contains a valid host and the same scheme as the parent request. If the target is a path, it will inherit the scheme and host of the parent request.
The
Push
method returnsiris.ErrPushNotSupported
if the client has disabled push or if push is not supported on the underlying connection.
Example
The Push
feature works only on HTTP/2 servers.
Create the project structure, e.g.
The main.js
contains a simple alert function:
Execute the following command to generate sample server keys:
Create the main.go
file and copy-paste the code below:
Run the server:
Now, open your browser's developer tools and click the Network
tab. Navigate to https://127.0.0.1/, the main.js
Initiator should be Push / (index)
as shown below:
Last updated