Eliminate flash of unstyled content

前端 未结 12 2006
一个人的身影
一个人的身影 2020-11-28 02:39

How do I stop the flash of unstyled content (FOUC) on a web page?

12条回答
  •  粉色の甜心
    2020-11-28 03:27

    A CSS-only solution:

    
      
        
        ...
      
      
        ...
         
      
    
    

    As the browser parses through the HTML file:

    • The first thing it will do is hide .
    • The last thing it will do is load the styles, and then display all the content with styling applied.

    The advantage to this over a solution that uses JavaScript is that it will work for users even if they have JavaScript disabled.

    Note: you are allowed to put inside of . I do see it as a downside though, because it violates common practice. It would be nice if there was a defer attribute for like there is for

提交回复
热议问题