Skip to content

Instantly share code, notes, and snippets.

@aganglada
Created September 22, 2017 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aganglada/61a023e31efe4f228338e91516dadf7b to your computer and use it in GitHub Desktop.
Save aganglada/61a023e31efe4f228338e91516dadf7b 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