Created
September 28, 2016 08:04
-
-
Save patrickkettner/f01855378f2e6165e5b254c968fca640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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/[email protected]/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