First thing you should understand is:
If your image has no semantic value, use the property background-image
+ display:none
in a div
, this will prevent your image from being loaded.
Issue
Looking at the situation, I realized that the answer I added above is not true, that is, at least in the case of Google Crome
this image is downloaded.
See for yourself:
div#image {
background-image: url("https://i.pinimg.com/736x/6b/b2/49/6bb249802cf0c124fde0ccbcea699340--funny-stuff-quotes.jpg");
width:500px;
height:500px;
display:none;
}
<div id='image'>
</div>
You can see this on the NetWork
tab, I also put an image to illustrate.
Whydoestheimageneedtoload?
BecauseScript
candynamicallycheckanelementofDOM
,thebrowserdoesnotoptimizeelementsortheircontents.
Source: Does "display: none" prevent an image from loading?