HTTP 2将支持服务器推送,这是什么意思? [英] HTTP 2 will support server push, what does this mean?

查看:289
本文介绍了HTTP 2将支持服务器推送,这是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多有关 HTTP 2 (目前仍在开发中)的内容,所以我也听说过服务器推送功能,但是我不明白.

I've read a lot of things about HTTP 2 (which is still in development), so I also heard about the server push feature, but I my head, this is not clear.

此服务器推送功能是否意味着服务器将能够向客户端发送响应而无需客户端发出请求?就像普通的TCP连接一样?还是我错过了重点?

Does this server push feature mean that the server will be able to send a response to the client without the latter making a request? Just like a vanilla TCP connection? Or I'm missing the point?

推荐答案

HTTP2推送机制不是通用的服务器推送机制,例如websocket或服务器发送的事件.

The HTTP2 push mechanism is not a generic server push mechanism like websocket or server sent events.

它专门用于HTTP对话的特定优化.具体来说,当客户端请求资源(例如index.html)时,服务器可以猜测它接下来将要请求一堆相关资源(例如theme.css,jquery.js,logo.png等).通常,一个网页可以包含10个此类相关请求.

It is designed for a specific optimisation of HTTP conversations. Specifically when a client asks for a resource (eg index.html) the server can guess that it is going to next ask for a bunch of associated resources (eg theme.css, jquery.js, logo.png, etc. etc.) Typically a webpage can have 10s of such associated requests.

使用HTTP/1.1,服务器必须等到客户端实际发送对这些关联资源的请求,然后客户端受到连接的限制,一次只能请求大约6个.因此,在实际发送网页所需的所有相关资源之前,可能要花费很多往返时间.

With HTTP/1.1, the server had to wait until the client actually sends request for these associated resources, and then the client is limited by connections to only ask for approx 6 at a time. Thus it can take many round trips before all the associated resources that are needed by a webpage are actually sent.

使用HTTP/2,服务器可以发送对index.html GET push promises的响应,以告知客户端它也将发送theme.css,jquery.js,logo.png等,就像客户已要求他们.然后,客户端可以取消这些推送或仅等待发送,而不会导致多次往返的额外延迟.

With HTTP/2, the server can send in the response to the index.html GET push promises to tell the client that it is going to also send theme.css, jquery.js, logo.png, etc. as if the client had requested them. The client can then cancel those pushes or just wait for them to be sent without incurring the extra latency of multiple round trips.

这是Jetty https://www.youtube.com上的SPDY(HTTP2的基础)推送示例. /watch?v = 4Ai_rrhM8gA .这是一个有关码头中HTTP2和SPDY的推送API的博客: https://webtide.com/http2-push-with-experimental-servlet-api/

Here is a demo of push with SPDY (the basis for HTTP2) with Jetty https://www.youtube.com/watch?v=4Ai_rrhM8gA . Here is a blog about the push API for HTTP2 and SPDY in jetty: https://webtide.com/http2-push-with-experimental-servlet-api/

这篇关于HTTP 2将支持服务器推送,这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆