This is a cross-browser solution optimized for modern browsers accepting CSS onload. It works back to 2011 when only Opera and Internet Explorer supported the onload event and onreadystatechange respectively on css. See link below.
var d = document,
css = d.head.appendChild(d.createElement('link')),
src = "https://unpkg.com/[email protected]/css/tachyons.css"
css.rel = 'stylesheet';
css.type = 'text/css';
css.href = src
Add this after the loader
if (typeof css.onload != 'undefined') css.onload = myFun;
else {
var img = d.createElement("img");
img.onerror = function() {
myFun();
d.body.removeChild(img);
}
d.body.appendChild(img);
img.src = src;
}
function myFun() {
/* ..... CONTINUE CODE HERE ..... */
}
The answer is based on this link that say:
What happens behind the scenes is that the browser tries to load the
CSS in the img element and, because a stylesheet is not a type of
image, the img element throws the onerror event and executes our
function. Thankfully, browsers load the entire CSS file before
determining its not an image and firing the onerror event.