Skip to content

Instantly share code, notes, and snippets.

@pxlrbt
Created June 11, 2020 09:04
Show Gist options
  • Save pxlrbt/eb1a11a7d037b2c366bd55d9ad5352e4 to your computer and use it in GitHub Desktop.
Save pxlrbt/eb1a11a7d037b2c366bd55d9ad5352e4 to your computer and use it in GitHub Desktop.
Polyfill
import waitForPolyfills from '@/polyfill/polyfill-helper';
waitForPolyfills(main);
function main() {
// ...
}
/**
* 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