Skip to content

Instantly share code, notes, and snippets.

@aholmes
Created February 6, 2015 18:18
Show Gist options
  • Save aholmes/2d156e95050cfe659728 to your computer and use it in GitHub Desktop.
Save aholmes/2d156e95050cfe659728 to your computer and use it in GitHub Desktop.
Load stylesheets after DOM render
var cb = function ()
{
var s = document.querySelector('head style:last-of-type');
['/path/to/stylesheet/one.css','/path/to/stylesheet/two.css']
.forEach(function (v)
{
var l = document.createElement('link'); l.rel = 'stylesheet'; l.href = v;
s.parentNode.appendChild(l, s);
});
}
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(cb);
else window.addEventListener('load', cb);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment