Created
April 8, 2013 20:28
-
-
Save paulfryzel/5340191 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var _scripts = [ | |
'/vendor/javascripts/jquery.js', | |
'/vendor/javascripts/moment.js', | |
'/vendor/javascripts/mixpanel.js', | |
'/javascripts/main.js' | |
]; | |
(function (scripts) { | |
'use strict'; | |
function downloadJSAtOnload() { | |
if (!scripts.length) { | |
return; | |
} | |
var element = document.createElement("script"); | |
element.src = scripts.shift(); | |
element.onload = element.onreadystatechange = function () { | |
if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') { | |
downloadJSAtOnload(); | |
} | |
}; | |
document.body.appendChild(element); | |
} | |
if (window.addEventListener) { | |
window.addEventListener("load", downloadJSAtOnload, false); | |
} else if (window.attachEvent) { | |
window.attachEvent("onload", downloadJSAtOnload); | |
} else { | |
window.onload = downloadJSAtOnload; | |
} | |
})(_scripts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment