Blog2014 ≫ Experimenting with deferred css loading

Some code here, 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](/wiki/#javascript)";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;

js: Programming language of the internets, mostly how I make my living.

💬 An update to that

⬅️ :: ➡️

Paul Clarkeʼs weblog - I live in Hythe near Folkestone, Kent. Wed to Clare and dad to 2, I am a full stack web developr, + I do mostly javascript / Node, some ruby, python, php ect ect. I like pubbing, parkrun, restaurants, home automation and other diy jiggery-pokery, history, genealogy, Television, squirrels, pirates, lego, and time travel.