Skip to content

jadjoubran/promyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promyfill

Promyfill saves you from shipping polyfill code to all browsers.
Your own polyfill URL will be loaded only if needed.

✅ Promyfill is ~450 Bytes.

Usage

Fetch example

const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';

promyfill(window.fetch, fetchPolyfill).then((fetch) => {
    //fetch is available (polyfill is fetched only if needed)
    fetch('users.json');
});

Alternate usage

const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';

promyfill('fetch' in window, fetchPolyfill).then(() => {
    //fetch is available (polyfill is fetched only if needed)
    fetch('users.json');
});

Intersection observer example

const ioPolyfill = 'https://rawgit.com/WICG/IntersectionObserver/gh-pages/polyfill/intersection-observer.js';

promyfill('IntersectionObserver' in window, ioPolyfill).then(() => {
    const io = new IntersectionObserver(() => {});
})

"Promises" support

Promyfill relies on native promises available in most modern browsers, except a few such as IE11, Android 4.4].
In order to support these browsers, you can also include the tiny promis from bramstein

Video explanation

Promyfill video

Feedback

This is a PWA experiment, usage & motivation detailed in this Medium article
For feedback or questions, please open a new issue.

About

🔥 450Bytes Promise based conditional polyfill loader

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published