Skip to content

Instantly share code, notes, and snippets.

@nantcom
Last active February 15, 2020 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nantcom/724c72a5322c3a24a3c45165ff34b1d6 to your computer and use it in GitHub Desktop.
Save nantcom/724c72a5322c3a24a3c45165ff34b1d6 to your computer and use it in GitHub Desktop.
Sample Script to Defer Loading Resources
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