
window.fetch polyfill
A browser polyfill that adds window.fetch to older browsers that lack it.JakeChampion/fetch
- Stars
- 25.8k
- Forks
- 2.8k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 2.3 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
This project provides a fetch() function for making web requests from JavaScript in the browser, for browsers that do not support fetch natively. It implements a subset of the Fetch specification so it can replace most XMLHttpRequest uses in traditional web apps. The README notes that modern browsers already have fetch built in, so the code has no effect there.
- Fetching JSON from an API and parsing it with response.json()
- Posting form data or JSON to a server with POST requests
- Uploading files using FormData
- Aborting in-flight requests in browsers with a native but outdated fetch
Great for
- Front-end developers maintaining web apps that must support older browsers
- Teams replacing XMLHttpRequest code with a Promise-based API
- Projects that import a package and want window.fetch available automatically
Not ideal for
- Modern-browser-only projects, because native fetch already exists and the polyfill does nothing there
- Node.js or server-side code, because the README says it does not work under Node.js
- Apps needing redirect modes, cache options, or keepalive, because the README says these are ignored or unsupported
How to get it
- 1
Install with a package manager
You'll need: npm
Install the package
npm install whatwg-fetch --save - 2
Run it
- Install the package with npm.
- Add import 'whatwg-fetch' near the top of your browser entry file.
- Call fetch('/users.json') and read the result with response.json().
- Check response.ok or response.status yourself, since HTTP errors do not reject the promise.
- 3
Get the most out of it
- Use the named import to call the polyfill directly in browsers with an outdated native fetch that lacks abort support.
- Set credentials: 'same-origin' explicitly when targeting Firefox 39-60, Chrome 42-67, or Safari 10.1-11.1.2.
- Add a Promise polyfill such as taylorhakes/promise-polyfill for older browsers, as the README recommends.
- Wrap fetch with a status-check function to reject on non-2xx responses, as shown in the README.
Downloads
Strengths
- Small, focused drop-in that follows the Fetch specification API
- MIT licensed and widely used, with about 25.8k GitHub stars
- README gives clear examples for common tasks like JSON, forms, and uploads
Trade-offs
- Only implements a subset of the Fetch spec; redirect and cache options are ignored
- Needs a separate Promise polyfill for older browsers, and CORS and cookie behavior depend on the browser
- Browser-only; the README says it does not work under Node.js
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| fetch (this) | 25.8k | Library | beginner | 2.3 years ago | Front-end developers maintaining web apps that must support older browsers |
| axios | 109k | Library | beginner | 4 days ago | JavaScript developers calling REST or other HTTP APIs from a browser front end |
| ky | 17.1k | Library | beginner | 28 days ago | JavaScript or TypeScript developers who already use fetch and want less boilerplate |
| got | 15k | Library | beginner | 7 days ago | Node.js developers who call web APIs from server-side code |
| query | 50.5k | Library | intermediate | 4 days ago | Frontend developers building apps that load data from a server |
| swr | 32.5k | Library | intermediate | 20 days ago | React developers who fetch data from APIs in components |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.