Last active
February 15, 2020 14:03
-
-
Save nantcom/724c72a5322c3a24a3c45165ff34b1d6 to your computer and use it in GitHub Desktop.
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