Skip to content

Instantly share code, notes, and snippets.

@Jekins
Created September 29, 2017 16:04
Show Gist options
  • Save Jekins/3495b87fd1ed5c01b8cc67e55147b5da to your computer and use it in GitHub Desktop.
Save Jekins/3495b87fd1ed5c01b8cc67e55147b5da to your computer and use it in GitHub Desktop.
Loading styles to head from noscript
<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