Blog2014 ≫ Experimenting with deferred css loading

Some code here1, I'm trying it out on something for work, will give it a go on this site later. The theory being if I have some css (what you use to style a webpage) that is styling something that you can't see straight away, then load those rules later. You want the page to appear asap, don't worry about styling that stuff that you have to scroll down to until you are likely to see it. Not sure if my idea of setting a timeout to do it is good or not. Will test it compared to this snippet from the google:

function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;

💬 An update to that

⬅️ :: ➡️

Paul Clarke's weblog - I live in Hythe in Kent. Married + dad to two, I'm a full stack web engineer, + I do js / nodejs, some ruby, other languages ect ect. I like pubs, running, eating, home automation + other diy jiggery-pokery, history, genealogy, TV, squirrels, pirates, lego, and TIME TRAVEL.