Last active
January 20, 2023 15:46
-
-
Save johnpolacek/3827270 to your computer and use it in GitHub Desktop.
Prevent FOUC
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
<!-- Prevent FOUC (flash of unstyled content) - http://johnpolacek.com/2012/10/03/help-prevent-fouc/ --> | |
<style type="text/css"> | |
.no-fouc {display: none;} | |
</style> | |
<script type="text/javascript"> | |
document.documentElement.className = 'no-fouc'; | |
// add to document ready: $('.no-fouc').removeClass('no-fouc'); | |
</script> |
Woow, simply the best one I've ever tried. My use case is inline critical CSS not fully capture above the fold layout state and would flash upon the main CSS loads. Thank you for this.
This doesn't work for external style sheets, does it? Since ready() doesn't care for them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! 👍 Thanks.