Skip to content

Instantly share code, notes, and snippets.

@felquis
Last active June 8, 2020 21:40
Show Gist options
  • Select an option

  • Save felquis/0473dfdb355e362ceb5a67097a0934f5 to your computer and use it in GitHub Desktop.

Select an option

Save felquis/0473dfdb355e362ceb5a67097a0934f5 to your computer and use it in GitHub Desktop.

Revisions

  1. felquis revised this gist Jun 8, 2020. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion load-global-javascript-async.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,18 @@
    /*
    Usage: loadJavaScriptFiles([{ src: 'cdn-path-to-file' }])
    Usage: loadJavaScriptFiles([{
    href:
    'https://path-to',
    },
    {
    href:
    'https://unpkg.com/cdn-path-to',
    integrity:
    'sha384',
    },
    {
    href: 'https://unpkg.com/path-to',
    },
    ])
    */
    const loadJavaScriptFiles = list => {
    return Promise.all(
  2. felquis revised this gist Jun 8, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion load-global-javascript-async.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /*
    Usage: loadJavaScriptFiles({ giveItAName: 'cdn-path-to-file' })
    Usage: loadJavaScriptFiles([{ src: 'cdn-path-to-file' }])
    */
    const loadJavaScriptFiles = list => {
    return Promise.all(
  3. felquis created this gist Jun 8, 2020.
    23 changes: 23 additions & 0 deletions load-global-javascript-async.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    /*
    Usage: loadJavaScriptFiles({ giveItAName: 'cdn-path-to-file' })
    */
    const loadJavaScriptFiles = list => {
    return Promise.all(
    list.map(file => {
    return new Promise((resolve, reject) => {
    const script = document.createElement('script');

    Object.keys(file).forEach(propertyName => {
    script[propertyName] = file[propertyName];
    });

    script.onload = () => resolve();
    script.onerror = () => reject();

    document.body.appendChild(script);
    });
    })
    );
    };

    module exports loadJavaScriptFiles