Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  37] [ 6]  / answers: 1 / hits: 130817  / 8 Years ago, mon, february 22, 2016, 12:00:00

I know that Fetch API uses Promises and both of them allow you to do AJAX requests to a server.



I have read that Fetch API has some extra features, which aren't available in XMLHttpRequest (and in the Fetch API polyfill, since it's based on XHR).



What extra capabilities does the Fetch API have?


More From » ajax

 Answers
13

There are a few things that you can do with fetch and not with XHR:




  • You can use the Cache API with the request and response objects;

  • You can perform no-cors requests, getting a response from a server that doesn't implement CORS. You can't access the response body directly from JavaScript, but you can use it with other APIs (e.g. the Cache API);

  • Streaming responses (with XHR the entire response is buffered in memory, with fetch you will be able to access the low-level stream). This isn't available yet in all browsers, but will be soon.



There are a couple of things that you can do with XHR that you can't do yet with fetch, but they're going to be available sooner or later (read the Future improvements paragraph here: https://hacks.mozilla.org/2015/03/this-api-is-so-fetching/):




  • Abort a request (this now works in Firefox and Edge, as @sideshowbarker explains in his comment);

  • Report progress.



This article https://jakearchibald.com/2015/thats-so-fetch/ contains a more detailed description.


[#63222] Saturday, February 20, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
daquanmilesw questions
;