http/2协议_HTTP / 2协议

HTTP/2协议是HTTP的当前版本,自2015年起被广泛采用,因为它提供了多路复用、标头压缩、服务器推送等性能优化特性。通过单一TCP连接实现请求和响应的多路复用,减少了HTTP/1.1的效率问题。此外,服务器推送允许预加载相关资源,二进制通讯则提高了解析效率。HTTP/2还实现了标头压缩,减少了数据交换量。未来,HTTP/3正在研发中,基于QUIC协议,有望进一步提高网络性能。
摘要由CSDN通过智能技术生成

http/2协议

I suggest to read the HTTP tutorial first

我建议先阅读HTTP教程

HTTP/2 is the current version of the HTTP protocol. Released in 2015 by the IETF (Internet Engineering Task Force) committee, it’s now widely adopted thanks to its unique features.

HTTP / 2是HTTP协议的当前版本。 由IETF(互联网工程任务组)委员会于2015年发布,由于其独特的功能,现在已被广泛采用。

HTTP/2 is way more performant than HTTP/1.1, the last version of HTTP that was available at the time.

HTTP / 2比HTTP / 1.1(当时可用的最新HTTP版本)性能更高。

The speed bump offered by HTTP/2 was so inviting that it was very quickly adopted - with a simple change in the Web Server (since HTTP/2 is 100% backwards compatible with HTTP/1.1), your websites and web apps now are working much faster automatically, which in turn is beneficial for your users and also for SEO purposes (as speed is a crucial factor for ranking).

HTTP / 2提供的减速功能非常吸引人,因此很快就被采用-通过对Web服务器进行简单的更改(因为HTTP / 2与HTTP / 1.1向下兼容100%),您的网站和Web应用现在可以正常工作自动更快,这反过来对您的用户和SEO都有利(因为速度是排名的关键因素)。

How can HTTP/2 be much faster than HTTP/1.1? The reasons are many, all oriented towards reducing the inefficiencies of the previous version, and introducing features that can allow browsers to be more capable of serving resources quicker.

HTTP / 2如何比HTTP / 1.1快得多? 原因很多,所有的原因都是为了减少先前版本的效率低下,并引入可使浏览器更快地提供资源的功能。

The main features of the new version of the protocol are:

该协议新版本的主要功能是:

  • request and response multiplexing

    请求和响应多路复用
  • efficient compression of HTTP headers

    有效压缩HTTP标头
  • server push

    服务器推送
  • binary communication

    二进制通讯

多路复用 (Multiplexing)

Before HTTP/2, only one response could be served at a time per each TCP connection.

在HTTP / 2之前,每个TCP连接一次只能提供一个响应。

TCP is the underlying protocol on top of which HTTP is built. TCP stays at the transport layer, while HTTP at the application level.

TCP是在其上构建HTTP的基础协议。 TCP停留在传输层,而HTTP停留在应用程序级别。

HTTP/2 enabled request/response multiplexing on top of a single TCP connection, allowing the server to serve multiple requests with the same connection resulting in a much faster communication.

在单个TCP连接的顶部启用了HTTP / 2的请求/响应多路复用,允许服务器使用相同的连接来服务多个请求,从而实现更快的通信。

This is the single change that will be a great benefit for your application, and makes several optimization techniques obsolete, including image sprites (which is used to combine several images in a single one, which is then “demultiplexed” by using a special CSS technique) and domain sharding, another hack used to prevent the browser limit of number of simultaneous connections to the same domain.

这是单个更改,它将对您的应用程序带来巨大好处,并且使一些优化技术过时了,包括图像精灵(用于将多个图像合并为一个图像,然后使用特殊CSS技术对其进行“多路分解”) )和域分片,这是另一种用于防止浏览器限制到同一域的同时连接数量的黑客。

标头压缩 (Headers compression)

HTTP Headers on pages and resources can grow quite big, considering a normal use of cookies and other header values. Compression enables HTTP to have a lighter footprint, reducing the amount of data exchanged between the client and the server.

考虑到Cookie和其他标头值的正常使用,页面和资源上的HTTP标头可能会变得很大。 压缩使HTTP的占用空间更小,从而减少了客户端和服务器之间交换的数据量。

服务器推送 (Server push)

Server push is a feature that allows to send multiple responses to a single request. Since the server knows that when requesting a resource a client will then request other complementary resources (think CSS, JS, images linked to a page) a server can decide to send them immediately.

服务器推送是一项功能,它允许向单个请求发送多个响应。 由于服务器知道在请求资源时客户端将随后请求其他补充资源(例如CSS,JS,链接到页面的图像),因此服务器可以决定立即发送它们。

Instead of sending the HTML, waiting for the browser to parse it and fire other requests to get the assets, the server can push them altogether.

服务器无需发送HTML,而是等待浏览器对其进行解析并触发其他获取资产的请求,而是可以将其完全推送。

A server can also decide to send resources that might be needed in future requests, pre-optimizing the next page load and putting it in the client cache.

服务器还可以决定发送将来请求中可能需要的资源,从而预先优化下一个页面加载并将其放入客户端缓存。

Note that server push can have its own drawbacks as well - for example, you can risk sending too much data to the client that might not be needed (maybe it’s already available on the client as cached), so use with caution

请注意,服务器推送也可能有其自身的缺点-例如,您可能会冒险向客户端发送过多的数据,而这些数据可能不需要(可能已在客户端上以缓存的形式提供),因此请谨慎使用

二进制通讯 (Binary communication)

HTTP/1.1 used text-based communication. HTTP/2 uses binary communication, which has a few advantages, including being more efficient to parse, less error prone and also more compact.

HTTP / 1.1使用基于文本的通信。 HTTP / 2使用二进制通信,它具有一些优点,包括解析效率更高,更不易出错且更紧凑。

未来会有什么发展? (What’s the evolution for the future?)

HTTP/3 is under development, and will be adapted from HTTP-over-QUIC, an experimental project.

HTTP / 3正在开发中,并将根据实验项目HTTP-over-QUIC进行改编。

QUIC is a protocol based on UDP (rather than TCP) at the transport layer, which means that HTTP/3 will be based on a completely different tech stack compared to HTTP/2 and HTTP/1.x.

QUIC是在传输层基于UDP(而不是TCP)的协议,这意味着与HTTP / 2和HTTP / 1.x相比,HTTP / 3将基于完全不同的技术堆栈。

翻译自: https://flaviocopes.com/http-2/

http/2协议

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值