Does “display:none” prevent an image from loading?

前端 未结 17 1911
再見小時候
再見小時候 2020-11-22 05:13

Every responsive website development tutorial recommends using the display:none CSS property to hide content from loading on mobile browsers so the website load

17条回答
  •  别那么骄傲
    2020-11-22 05:37

    Use @media query CSS, basically we just release a project where we had an enormous image of a tree on desktop at the side but not showing in table/mobile screens. So prevent image from loading its quite easy

    Here is a small snippet:

    .tree {
        background: none top left no-repeat; 
    }
    
    @media only screen and (min-width: 1200px) {
        .tree {
            background: url(enormous-tree.png) top left no-repeat;
        }
    }
    

    You can use the same CSS to show and hide with display/visibility/opacity but image was still loading, this was the most fail safe code we came up with.

提交回复
热议问题