当前的XHR实现是否利用HTTP/2? [英] Do current XHR implementations take advantage of HTTP/2?

查看:144
本文介绍了当前的XHR实现是否利用HTTP/2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能只是突出了我的一些误解,但我很好奇:

This may just highlight some misconception of mine, but I was curious:

如果您运行的是HTTP/2服务器,并且想在浏览器中向服务器提出XHR请求,那么XHR是否会自动利用标头中的性能优化,并提供这种性能?

If you had an HTTP/2 server running and wanted to make XHR requests in the browser to the server, would XHR automatically take advantage of the performance optimisations in headers and such that it provides?

还是会忽略该功能并作为HTTP请求运行?如果是这样,我们可以做些什么来在请求中使用新的优化方法?

Or would it ignore that functionality and operate as an HTTP request? If so, are there any things we can do to use the new optimisations in our requests?

推荐答案

您无需执行任何操作.如果服务器支持HTTP/2,则XHR将使用它.标头压缩等将自动启动.

You don't need to do anything. If the server supports HTTP/2, XHR will use it. Header compression and such will kick in automatically.

测试:

  • 在Chrome中打开一个HTTP/2网站.您还可以使用我们的来检查有关HTTP/2 PUSH,AngularJS和RequireJS的一些很棒的内容.
  • 打开Devtools面板(F12),然后打开网络面板,然后单击XHR.右键点击标题行,并确保您拥有协议"列已启用.
  • 您应该看到"h2"在上述专栏中(在我们的示例中,AngularJS正在通过XHR加载包含模板).
  • 此时,请注意服务器已推送XHR请求.推送响应的明显迹象是临时标头"而不是请求标头,并且异常小的下载"和等待"时代.我们甚至在响应中添加了额外的标题(x-shimmmercat-note:pushed-stream).浏览器接受了此请求,因此 XHR请求不仅将使用HTTP/2(如果可用),而且在某些情况下可以使用推送的资源.
  • Open an HTTP/2 website in Chrome. You can use ours, to also checkout some cool stuff regarding HTTP/2 PUSH, AngularJS and RequireJS.
  • Open Devtools panel (F12), then the network panel, and then click XHR. Right click the headers row, and ensure you have the "Protocol" column enabled.
  • You should see "h2" in said column ( in our case, AngularJS is loading a template include through XHR).
  • While you are at that, notice that the server pushed the XHR request. Tell-tale signs of pushed responses are "provisional headers" instead of request headers, and abnormally small "download" and "waiting" times. We even add an extra-header to the response (x-shimmmercat-note:pushed-stream) . The browser adopted this request, so XHR requests not only will use HTTP/2 if available, but can in some cases use pushed resources.

这篇关于当前的XHR实现是否利用HTTP/2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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