Created
June 11, 2020 09:04
-
-
Save pxlrbt/eb1a11a7d037b2c366bd55d9ad5352e4 to your computer and use it in GitHub Desktop.
Polyfill
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
import waitForPolyfills from '@/polyfill/polyfill-helper'; | |
waitForPolyfills(main); | |
function main() { | |
// ... | |
} |
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
/** | |
* Check for needed function and load polyfills in case | |
*/ | |
function waitForPolyfills(entry) { | |
if ('assign' in Object) { | |
return entry(); | |
} | |
console.log('Load Polyfills', window.polyfill_uri); | |
return loadScript(window.polyfill_uri, entry); | |
} | |
/** | |
* Load a script ressource and execute callback afterwards | |
*/ | |
function loadScript(src, callback) { | |
var js = document.createElement('script'); | |
js.src = src; | |
js.onload = function() { | |
callback(callback); | |
}; | |
js.onerror = function() { | |
callback(callback); | |
}; | |
document.head.appendChild(js); | |
} | |
export default waitForPolyfills; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment