Do current XHR implementations take advantage of HTTP/2?

拈花ヽ惹草 提交于 2019-12-03 22:49:28

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.

Test it:

  • 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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!