How to prevent the white 'flash' on page load created by background image loading delay?

后端 未结 6 1901
不知归路
不知归路 2020-12-23 09:35

The problem is, on most sites on the web, there are background images. They take time to load. Ordinarily, it wouldn\'t be a problem if the images were optimized, and small

6条回答
  •  醉话见心
    2020-12-23 10:26

    I was having the same issue and found it pretty strange that this isn't talked about more. I still haven't found any documentation on this, but please comment if you find anything regarding RFC's for css background image loading priorities, etc.

    Anyways, the only thing I found is that load immediately while background-image() seems to load on dom ready.

    So my solution was to place a with display:none just before the

    with the background image. This will load the image immediately and then it gets used immediately for the background-image.

    
    
    • One thing to note is that you could still get flickering on images that are not optimized. So for jpg's make sure to compress them and set the "progressive" attribute when creating them.

提交回复
热议问题