There are two ways to fetch resources.
- Using
XMLHTTPRequest(XHR for short) - Using the Fetch API
Both XHR and Fetch are well supported on all browsers so you can use either method.
XHR vs Fetch
There are two major differences:
- XHR uses callbacks while Fetch uses Promises.
- You can use Fetch in services workers, but you cannot use XHR in it.
Most people prefer Fetch over XHR because it’s newer and uses Promises.
But this difference doesn’t matter in reality because we usually use libraries for the fetching process.
Libraries are helpful because XHR and Fetch are low-level APIs. If you use raw XHR and Fetch, you will have to write repetitive boilerplate code that libraries already help you with.
What you’re going to learn
In this course, you’re going to learn how to use:
- XHR
- Fetch
- A library called zlFetch
In the next two lessons, you’ll learn how to use both XHR and Fetch in their raw forms. This will give you the confidence to know what going on when you use a library.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson