DEV Community

Discussion on: What To Expect When You're Expecting To Drop IE11 πŸ—‘οΈ

Collapse
 
peiche profile image
Paul

Using XHR instead of the fetch API is not out of the question. Fetch isn't a 1:1 replacement, and as Chris Ferdinandi points out, requires two functions just to get the data in readable form. (In the first then() the data is in a stream.) Another great post by Glenn Stovall demonstrates how to write a small ajax function using XHR without any third party libraries.

Collapse
 
samthor profile image
Sam Thorogood

You're not wrong, and the extra step is a bit misunderstood, although important if you want to stream large binary files (I used it in this PWA demo to show a %β€”blink and you'll miss it).

I have a few unrelated thoughts:

  • await makes the flow much nicer than Chris' examples
  • I'm also surprised neither link uses onload, instead using the more confusing onreadystatechange (and this is actually a vote for XHRs).
  • the lack of support for responseType = 'json' in IE11 actually makes XHRs more confusing, since you just can't safely use that parameter and you have to add a JSON.parse call too