JS-only CSS
Do you have CSS that is only used when you have JS enabled? Are you trying to avoid some flickering of pre-JS-ified content? Then put that CSS in its own JavaScript-specific CSS file and write it to your HTML via one of two options.
- Good ol’ document.write()
<script type="text/javascript"> //<![CDATA[ document.write('<link rel="stylesheet" href="js.css" type="text/css" />'); //]]> </script> - Slick new DOM:
<script type="text/javascript"> //<![CDATA[ var lnk = document.createElement('link'); lnk.setAttribute('rel', 'stylesheet'); lnk.setAttribute('type', 'text/css'); lnk.setAttribute('href', 'js.css'); document.getElementsByTagName('head')[0].appendChild(lnk); //]]> </script>
Tip to PPK and Tino Zijdel (comment 8).