Created
September 29, 2017 16:04
-
-
Save Jekins/3495b87fd1ed5c01b8cc67e55147b5da to your computer and use it in GitHub Desktop.
Loading styles to head from noscript
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
<noscript id="styles"> | |
<link rel="stylesheet" href="style1.css"> | |
<link rel="stylesheet" href="style2.css"> | |
</noscript> | |
<script> | |
var head = document.getElementsByTagName('head')[0], | |
stylesString = document.getElementById('styles').childNodes[0].textContent, | |
stylesRegex = /[^"]+\.css/g, | |
stylesResult = stylesString.match(stylesRegex); | |
for (var i = 0; i < stylesResult.length; i++) { | |
var link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.href = stylesResult[i]; | |
head.appendChild(link); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment