Fetch API
The Fetch API provides an interface for fetching resources (including across the network). It is a more powerful and flexible replacement for XMLHttpRequest.
Concepts and usage
The Fetch API uses Request and Response objects (and other things involved with network requests), as well as related concepts such as CORS and the HTTP Origin header semantics.
For making a request and fetching a resource, use the fetch() method. It is a global method in both Window and Worker contexts. This makes it available in pretty much any context you might want to fetch resources in.
The fetch() method takes one mandatory argument, the path to the resource you want to fetch. It returns a Promise that resolves to the Response to that request — as soon as the server responds with headers — even if the server response is an HTTP error status. You can also optionally pass in an init options object as the second argument (see Request).
Once a Response is retrieved, there are a number of methods available to define what the body content is and how it should be handled.
You can create a request and response directly using the Request() and Response() constructors, but it's uncommon to do this directly. Instead, these are more likely to be created as results of other API actions (for example, FetchEvent.respondWith() from service workers).
Find out more about using the Fetch API features in Using Fetch.
Deferred Fetch
The fetchLater() API enables a developer to request a deferred fetch, that can be sent after a specified period of time, or when the page is closed or navigated away from. See Using Deferred Fetch.
Interfaces
Window.fetch()andWorkerGlobalScope.fetch()-
The
fetch()method used to fetch a resource. Window.fetchLater()-
Used to make a deferred fetch request.
DeferredRequestInit-
Represents the set of options that can be used to configure a deferred fetch request.
FetchLaterResult-
Represents the result of requesting a deferred fetch.
Headers-
Represents response/request headers, allowing you to query them and take different actions depending on the results.
Request-
Represents a resource request.
Response-
Represents the response to a request.
HTTP headers
deferred-fetch-
Controls the top-level quota for the
fetchLater()API. deferred-fetch-minimal-
Controls the shared cross-origin subframe quota for the
fetchLater()API.
Specifications
| Specification |
|---|
| Fetch # fetch-method |
| Fetch # deferred-fetch |
Browser compatibility
api.fetch
| desktop | mobile | server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fetch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Authorization header removed from cross-origin redirects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Support for blob: and data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options parameter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attributionReporting property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReadableStream body
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browsingTopics property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
duplex property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keepalive property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
priority property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
privateToken property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
referrerPolicy property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signal property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
targetAddressSpace property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Non-standard. Check cross-browser support before using.
- Deprecated. Not for use in new websites.
- See implementation notes.
- Has more compatibility info.
api.Window.fetchLater
| desktop | mobile | server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fetchLater
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- See implementation notes.