Coder Social home page Coder Social logo

this-package-uses-fetch's Introduction

This Package Uses Fetch

If you've landed here from a JavaScript package's documentation, it means that the aforementioned package uses fetch internally, and wants to help you polyfill it if needed.

For more information on why we created this document, visit our blog post.

Do I need a polyfill?

Here's a brief definition of a polyfill:

A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older environments that do not natively support it.

In the case of fetch, this will primarily be:

  • Browsers: Opera Mini & IE
  • Server: Node v17 or lower

Therefore, if you fit one of the following scenarios:

  • plan on using the package in a webapp, and you have data that indicates that your users might be on these older browsers (e.g. by importing your analytics into https://caniuse.com/ciu/import)
  • plan on using the package in a Node.js server that's on v17 or below

then you might want to keep reading. Otherwise, you don't need to do anything!

Polyfills

There are many polyfills out there, but here are the ones we'll recommend:

Adding polyfills

To polyfill fetch in the global scope, you'll have to do the following in your application's entry point (or at least, before the package that needs fetch is imported):

  • server:
import fetch from 'node-fetch';
globalThis.fetch = fetch;

// only import the package _after_
import packageThatUsesFetch from 'package-that-uses-fetch';
  • browser:
// browser
import 'whatwg-fetch';

// only import the package _after_
import packageThatUsesFetch from 'package-that-uses-fetch';

From then on, you're free to use the package as you see fit.

this-package-uses-fetch's People

Contributors

samijaber avatar arjunyel avatar

Stargazers

Micah Snyder avatar 代码即是地狱 avatar Kevin Restaino avatar Adrián Mouly avatar Gil Barbara avatar Elias Wambugu avatar

Watchers

Nick Khan avatar Steve Sewell avatar  avatar Aziz Abbas avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.