Created
January 5, 2018 14:45
-
-
Save luan0ap/31ccd6168566819dc744c3d28b83483d to your computer and use it in GitHub Desktop.
Loading polyfill only when needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const browserSupportsAllFeatures = () => window.Promise && window.fetch && window.Symbol | |
const loadScript = (src = '', done) => { | |
var js = document.createElement('script') | |
js.src = src | |
document.head.appendChild(js) | |
return done() | |
} | |
if (browserSupportsAllFeatures()) { | |
// Browsers that support all features run `main()` immediately. | |
main() | |
} else { | |
// All other browsers loads polyfills and then run `main()`. | |
loadScript('/path/to/polyfills.js', main) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment