THE FETCH API
The Fetch API can perform all the same tasks as an XMLHttpRequest
object, but is much easier to use, has a more modern interface, and is able to be used by modern web tools like web workers. Whereas the XMLHttpRequest
is optionally asynchronous, all requests dispatched by the Fetch API are strictly asynchronous. The Fetch API is a WHATWG living standard specification, which can be found at https://fetch.spec.whatwg.org/
. The specification puts it best: “The Fetch standard defines requests, responses, and the process that binds them: fetching.”
The Fetch API itself is a superior tool for requesting resources in JavaScript, but the API is also relevant in the domain of service workers in that it provides an interface for intercepting, redirecting, and altering requests made via fetch()
.
Basic API Utilization
The fetch()
method is available in any global scope, both in the primary page execution, modules, and inside workers. Invoking it will instruct the browser...