Last active
September 21, 2015 20:57
-
-
Save mszynka/e9969dff0712c7c3372a to your computer and use it in GitHub Desktop.
CSS stylesheet lazyloader
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
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta charset="utf-8"> | |
<title>LazyLoader</title> | |
<noscript> | |
<link href="style.css" rel="stylesheet"> | |
</noscript> | |
</head> | |
<body> | |
<script src="script.js"></script> | |
</body> | |
</html> |
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
function lazyLoadStyles(element, cssClass) { | |
var head = document.getElementsByTagName('head')[0]; | |
var css = head.querySelector(element + "." + cssClass); | |
var links = document.createElement('div'); | |
links.innerHTML = css.textContent; | |
while (links.childNodes.length) | |
head.appendChild(links.firstChild); | |
head.getElementsByTagName('noscript')[0].remove(); | |
} | |
window.onload = function() { | |
lazyLoadStyles("noscript", "lazyload") | |
} |
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
html,body { | |
width: 100%; | |
height: 100%; | |
background-color: green; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment