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

前端 未结 17 2291
再見小時候
再見小時候 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:38

    Browsers are getting smarter. Today your browser (depending on the version) might skip the image loading if it can determine it's not useful.

    The image has a display:none style but its size may be read by the script. Chrome v68.0 does not load images if the parent is hidden.

    You may check it there : http://jsfiddle.net/tnk3j08s/

    You could also have checked it by looking at the "network" tab of your browser's developer tools.

    Note that if the browser is on a small CPU computer, not having to render the image (and layout the page) will make the whole rendering operation faster but I doubt this is something that really makes sense today.

    If you want to prevent the image from loading you may simply not add the IMG element to your document (or set the IMG src attribute to "data:" or "about:blank").

提交回复
热议问题