简体   繁体   中英

Http2 Server Push support

Quick question/clarification on using Server Push with Http2.

So, I installed libnghttp2, then compiled Apache 2.4.18 from source with http2 support and created some self signed certs to use https.

I then added in directive Protocols h2c http/1.1 and created a vhost including:

<Location /index.html>
    Header add Link "</css/site.css>;rel=preload"
</Location>

so I can test Server Push. Hitting my front end with Firefox I get the h2 header returned as well as a Link Header that's value is /css/site.css but my css isnt preloaded.. Not sure if I am fundamentally misunderstanding what Server Push is doing or not doing or whether I have done something wrong.

I've tried with a few variations of the css value and location value but with no success. Been googling for a while, but to no avail, so any point in the right direction would be great.

you can try again:

<Location /index.html>
Header add Link "</css/site.css>;rel=preload;as=style"

if you want to push image you should use " as=image"

Protocols h2c http/1.1

Choosing h2c will enable http/2 clear, which only a few command line browsers supprt. Since you're using Firefox it means that it will default to http/1.1, all major browsers support HTTP/2 over TLS only.
To see the current version Firefox chose you can use a plugin like this one or you can open the developer tools (F12) and click each resource to see the protocol's version used, as explained here
Your Headar add Link command looks fine.
You can test your current setup with nghttp or curl (check if the version you have supports HTTP/2) command line browsers

If your server side code is in java, try using PushBuilder object to push your documents to the client's end. The contents of your web-page will be cached into the client's browser in the order they have been pushed by the PushBuilder object. Ensure that you use only one PushBuilder object to push these documents.

Moreover, it is recommended that you use Protocols h2 http/1.1 instead of Protocols h2c http/1.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM