简体   繁体   English

Http2服务器推送支持

[英]Http2 Server Push support

Quick question/clarification on using Server Push with Http2. 有关在Http2中使用Server Push的快速问题/说明。

So, I installed libnghttp2, then compiled Apache 2.4.18 from source with http2 support and created some self signed certs to use https. 因此,我安装了libnghttp2,然后使用http2支持从源代码编译了Apache 2.4.18,并创建了一些使用https的自签名证书。

I then added in directive Protocols h2c http/1.1 and created a vhost including: 然后,我在指令Protocols h2c http / 1.1中添加了一个虚拟主机,其中包括:

<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. 使用Firefox达到我的前端,我得到了返回的h2标头以及值为/css/site.css的Link标头,但是我的css没有预加载。。不确定我是否从根本上误解了Server Push在做什么或不做什么?我是否做错了什么。

I've tried with a few variations of the css value and location value but with no success. 我尝试使用CSS值和位置值的一些变体,但没有成功。 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" 如果要推送图像,则应使用“ as = image”

Protocols h2c http/1.1 协议H2C http / 1.1

Choosing h2c will enable http/2 clear, which only a few command line browsers supprt. 选择h2c将启用http / 2 clear,只有少数命令行浏览器支持。 Since you're using Firefox it means that it will default to http/1.1, all major browsers support HTTP/2 over TLS only. 由于您使用的是Firefox,这意味着它将默认为http / 1.1,因此所有主流浏览器仅支持基于TLS的HTTP / 2。
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 要查看当前版本的Firefox选择,你可以使用插件像这一个 ,也可以打开开发者工具(F12),点击每一个资源,看惯了协议的版本,如解释在这里
Your Headar add Link command looks fine. 您的Headar add Link命令看起来不错。
You can test your current setup with nghttp or curl (check if the version you have supports HTTP/2) command line browsers 您可以使用nghttp或curl(检查您的版本是否支持HTTP / 2)命令行浏览器来测试当前设置

If your server side code is in java, try using PushBuilder object to push your documents to the client's end. 如果您的服务器端代码在Java中,请尝试使用PushBuilder对象将文档推送到客户端。 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. 网页的内容将按PushBuilder对象推送的顺序缓存到客户端的浏览器中。 Ensure that you use only one PushBuilder object to push these documents. 确保仅使用一个PushBuilder对象来推送这些文档。

Moreover, it is recommended that you use Protocols h2 http/1.1 instead of Protocols h2c http/1.1 此外,建议您使用协议h2 http / 1.1代替协议h2c http / 1.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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