Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do current XHR implementations take advantage of HTTP/2?

Tags:

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 server, would XHR automatically take advantage of the performance optimisations in headers and such that it provides?

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?

like image 586
Nick Jennings Avatar asked Sep 15 '15 17:09

Nick Jennings


1 Answers

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.
like image 57
dsign Avatar answered Sep 29 '22 10:09

dsign