Skip to content

Instantly share code, notes, and snippets.

@JTLR
Created February 10, 2014 11:05
Show Gist options
  • Save JTLR/8914025 to your computer and use it in GitHub Desktop.
Save JTLR/8914025 to your computer and use it in GitHub Desktop.
Lazy load external stylesheets (include before closing body tag)
window.onload = function() {
var head = document.getElementsByTagName('head')[0];
var link;
var stylesheets = [
{
href: '/path/to/stylesheet.css',
rel: 'stylesheet',
type: 'text/css'
},
{
href: '/path/to/stylesheet.css',
rel: 'stylesheet',
type: 'text/css'
},
{
href: '/path/to/stylesheet.css',
rel: 'stylesheet',
type: 'text/css'
}
];
for (var i = 0; i < stylesheets.length; i++) {
link = document.createElement('link');
link.type = stylesheets[i].type;
link.href = stylesheets[i].href;
link.rel = stylesheets[i].rel;
head.appendChild(link);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment