Skip to content

Instantly share code, notes, and snippets.

@pxlrbt
Created June 11, 2020 09:04
Show Gist options
  • Select an option

  • Save pxlrbt/eb1a11a7d037b2c366bd55d9ad5352e4 to your computer and use it in GitHub Desktop.

Select an option

Save pxlrbt/eb1a11a7d037b2c366bd55d9ad5352e4 to your computer and use it in GitHub Desktop.

Revisions

  1. pxlrbt revised this gist Jun 11, 2020. No changes.
  2. pxlrbt created this gist Jun 11, 2020.
    7 changes: 7 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    import waitForPolyfills from '@/polyfill/polyfill-helper';

    waitForPolyfills(main);

    function main() {
    // ...
    }
    30 changes: 30 additions & 0 deletions polyfill-helper.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    /**
    * 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;