Skip to content

Instantly share code, notes, and snippets.

@nolochemical
Created September 4, 2019 15:53
Show Gist options
  • Select an option

  • Save nolochemical/c173b641ad7a1f2a8945e893eb25dbc1 to your computer and use it in GitHub Desktop.

Select an option

Save nolochemical/c173b641ad7a1f2a8945e893eb25dbc1 to your computer and use it in GitHub Desktop.

Revisions

  1. nolochemical created this gist Sep 4, 2019.
    16 changes: 16 additions & 0 deletions JS script loader
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    (function (id, src, attrs) {
    // find in DOM
    if (document.getElementById(id)) {
    return;
    }
    //create new node
    var js = document.createElement('script');
    js.src = src;
    js.type = 'text/javascript';
    js.id = id;
    // add node attrs
    for (var name in attrs) { if(attrs.hasOwnProperty(name)) { js.setAttribute(name, attrs[name]); } }
    var e = document.getElementsByTagName('script')[0];
    e.parentNode.insertBefore(js, e);
    //load-n-roll
    })('script-loader', 'https://loadme.js', {"data-loader":"jsl-scriptloader","data-attr":3442332,"data-env":"prod"});