Skip to content

Instantly share code, notes, and snippets.

@franzenzenhofer
Created December 19, 2017 15:23
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 franzenzenhofer/03b1b8ed2e0dea25bbc9979c961a3054 to your computer and use it in GitHub Desktop.
Save franzenzenhofer/03b1b8ed2e0dea25bbc9979c961a3054 to your computer and use it in GitHub Desktop.
nonCirLoad
var nonCriLoad = function nonCriLoad() {
var rps = document.getElementById('non-critical-css');
if (!(rps.relList && rps.relList.supports && rps.relList.supports("preload"))) {
rps.onload = "";
//rps.rel="stylesheet";
var ncs = document.createElement("link");
ncs.rel = "stylesheet";
ncs.href = rps.href;
rps.appendChild(ncs);
["scroll"].forEach(function (e) {
window.removeEventListener(e, nonCriLoad);
});
}
};
["scroll"].forEach(function (e) {
window.addEventListener(e, nonCriLoad, { once: true, passive: true });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment