html - Preventing FOUC when calling CSS through a javascript -
i have webpage have altered template. suffering fouc (flash of unstyled content).
i have tried solution here: https://docs.google.com/presentation/d/1jt_vqc5ldf-e9j8wtxu4kzpa8itlmymntgy5tdcbgoy/present?slide=id.p
but not work. here main part of head, scripts calling css in (i think!).
<head> <!--[if lte ie 8]><script src="js/html5shiv.js"></script><![endif]--> <script src="js/jquery.min.js"></script> <script src="js/skel.min.js"></script> <script src="js/skel-layers.min.js"></script> <script src="js/init.js"></script> </head> <body id="top"> bunch of stuff hide until style has loaded. </body>
the idea of solution pause load of content until css has loaded, not sure whether work when calling java script.
here tried:
<head> <style type="text/css"> #fouc { display: none; } </style> <script type="text/javascript"> document.documentelement.classname = 'js'; </script> <!--[if lte ie 8]><script src="js/html5shiv.js"></script><![endif]--> <script src="js/jquery.min.js"></script> <script src="js/skel.min.js"></script> <script src="js/skel-layers.min.js"></script> <script src="js/init.js"></script> </head> <body id="top"> <div id="fouc"> bunch of stuff hide until style has loaded. </div> <script type="text/javascript"> document.getelementbyid("fouc").style.display="block"; </script> </body>
this did not work. can suggest way stop fouc in scenario?
thank patience, appreciate help,
j
this solution:
<script src="js/jquery.min.js"></script> <script src="js/skel.min.js"></script> <script src="js/skel-layers.min.js"></script> <script src="js/init.js"></script> <style type="text/css"> .no-fouc {display: none;} </style> <script type="text/javascript"> document.documentelement.classname = 'no-fouc'; $(window).on("load", function() { $('.no-fouc').removeclass('no-fouc'); }); </script>
this whole thing went <head> no changes <body>.
which rather using classes , id's in body section, uses $(window).on("load", function() load page once content loaded. sure load jquery before script block.
Comments
Post a Comment