Skip to content

Instantly share code, notes, and snippets.

@danwarfel
Last active April 10, 2017 08:46
Show Gist options
  • Save danwarfel/d8ed1a7f06f8dd393b79 to your computer and use it in GitHub Desktop.
Save danwarfel/d8ed1a7f06f8dd393b79 to your computer and use it in GitHub Desktop.
Defer Loading of External CSS Until Page Loaded
var cb = function() {
var l = document.createElement('link'); l.rel = 'stylesheet';
l.href = '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css';
var h = document.getElementsByTagName('head')[0]; h.insertBefore(l, h.lastChild);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(cb);
else if (window.addEventListener) window.addEventListener('load', cb);
else if (window.attachEvent) window.attachEvent("onload", cb);
else window.onload = cb;
// from http://codesr.thewebflash.com/2014/08/defer-loading-external-css-until-page.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment