Created
February 10, 2014 11:05
-
-
Save JTLR/8914025 to your computer and use it in GitHub Desktop.
Lazy load external stylesheets (include before closing body tag)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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