Skip to content

Instantly share code, notes, and snippets.

@patrickkettner
Created September 28, 2016 08:04
Show Gist options
  • Save patrickkettner/f01855378f2e6165e5b254c968fca640 to your computer and use it in GitHub Desktop.
Save patrickkettner/f01855378f2e6165e5b254c968fca640 to your computer and use it in GitHub Desktop.
// grab a reference to all scripts on the page, keep in mind this
// will only include all of the <script> elements that have been
// parsed up until this point
var scripts = document.getElementsByTagName('script');
// cheat and use currentScript if it exists, otherwise grab the last
// script tag, which will be the current running script tag sense the
// getElements call can't see nodes in the future
var currentScript = document.currentScript || scripts[scripts.length - 1];
// simple script adder
var add = function(url) {
var s = document.createElement('script');
s.src = url;
// insert the next script tag after the current tag
currentScript.parentNode.insertBefore(s, currentScript.nextSibling
}
// load yer polyfills without using document.write
window.Promise || add("https://unpkg.com/es6-promise@3.2.1/dist/es6-promise.min.js"; currentScript.parent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment