Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zheeeng/700bf92614a7ebfcffdde637aa4b8d0c to your computer and use it in GitHub Desktop.
Save zheeeng/700bf92614a7ebfcffdde637aa4b8d0c to your computer and use it in GitHub Desktop.
loadPolyfills()
.then(() => /* Render React application now that your Polyfills are ready */)
/**
* Do feature detection, to figure out which polyfills needs to be imported.
**/
function loadPolyfills() {
const polyfills = []
if (!supportsIntersectionObserver()) {
polyfills.push(import('intersection-observer'))
}
return Promise.all(polyfills)
}
function supportsIntersectionObserver() {
return (
'IntersectionObserver' in global &&
'IntersectionObserverEntry' in global &&
'intersectionRatio' in IntersectionObserverEntry.prototype
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment