Ming Zhu
Ming Zhu

Reputation: 282

does HTTP/2 work in CORS request?

index.html is loaded from server https://foo.com, which supports http 1.1 only, but with proper CORS header, an XMLHttpRequest can be sent out to a 2nd server https://bar.com, which supports http/2.

Will my application be able to leverage the http/2 features between the browser and server https://bar.com?

Upvotes: 0

Views: 3209

Answers (2)

Barry Pollard
Barry Pollard

Reputation: 46040

Yes, it's a completely separate connection but I doubt it will matter as not sure what "features" you hope to benefit from?

Nearly all of the features and advantages of HTTP/2 are designed to improve performance of many connections to the same domain:

  • Proper Multiplexing allows you to make many requests over a single connection while removing the head of line blocking seen under HTTP/1.1.
  • Prioritisation looks to ensure the multiplexed connection is used efficiently.
  • Header Compression allows similar HTTP Headers to be sent over multiple requests without a performance penalty (e.g. large numbers of cookies being sent with every request).
  • Binary format is more a technical change to make writing software that parses HTTP requests (e.g. webservers and web browsers) more robust - especially relevant when multiplexing.

So unless your website is making huge numbers of XMLHttpRequests to the same host those features won't really benefit you that much. The overheads of HTTP/2 coupled with the implementations being fairly new and so probably not 100% optimal yet, will often mean that HTTP/2 could actually be slower for small numbers of requests.

That only leaves Server Push. This can only be sent in response to an original request, so is less beneficial for XMLHttpRequests in most cases. Additionally there seems to be some confusion as to how to handle pushed XMLHttpRequests.

Upvotes: 2

sbordet
sbordet

Reputation: 18617

Yes, your application will be able to leverage the HTTP/2 features provided by bar.com.

This is also why CDNs providers are so interested in HTTP/2.

XMLHttpRequest is no different: the browser still makes a HTTP request (whether it's to a CDN or via XMLHttpRequest), and if bar.com supports HTTP/2, the browser will make the call using HTTP/2.

Upvotes: 0

Related Questions