Do current XHR implementations take advantage of HTTP/2?

后端 未结 1 1024
星月不相逢
星月不相逢 2021-01-03 22:28

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

If you had an HTTP/2 server running and wanted to make XHR requests in the browser to the ser

相关标签:
1条回答
  • 2021-01-03 22:49

    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.
    0 讨论(0)
提交回复
热议问题