Last active
February 15, 2020 14:03
Sample Script to Defer Loading Resources
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
var delayStack = 100; | |
window.deferCSS = function (url) { | |
var link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.href = url; | |
link.type = 'text/css'; | |
delayStack += 10; | |
window.setTimeout(function () { | |
document.getElementsByTagName("head")[0].appendChild(link); | |
}, delayStack); | |
}; | |
window.deferCss = window.deferCSS; // prevent my forgetfulness | |
window.deferScript = function (url, delay) { | |
var script = document.createElement('script'); | |
script.src = url; | |
script.type = "text/javascript"; | |
delayStack += 10; | |
window.setTimeout(function () { | |
document.getElementsByTagName("head")[0].appendChild(script); | |
}, delay == null ? delayStack : delay); | |
}; | |
// Sample | |
window.deferCSS('/NancyBlack/Modules/ContentSystem/ncb-content.min.css'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment