3

If I have a div with some heavy loading content in it like some large pictures. Will my site load the content of this div if it is set to display none in my stylesheet or will the div and its content be ignored and not loaded?

Robin Cox
  • 1,392
  • 2
  • 13
  • 30
  • 4
    Content will be loaded. – sinisake Jun 13 '13 at 17:27
  • 1
    [you may want to check this browser request trivia game out](http://jakearchibald.github.io/request-quest/). – zzzzBov Jun 13 '13 at 17:28
  • possible duplicate of [Does "display:none" prevent an image from loading?](http://stackoverflow.com/questions/12158540/does-displaynone-prevent-an-image-from-loading) – cimmanon Jun 13 '13 at 18:28

3 Answers3

7

As per Request Quest:

Browsers download imagery regardless of parent styles

for anyone who can't read the image
<div style="display: none"><img src="img.png"></div>

Does the above trigger a request for img.png in any of the following:

Chrome, Safari, Firefox, IE

Correct! The request was made in Chrome, Safari, Firefox & IE.

Aha! Yes, browsers download imagery regardless of style, as per the spec.

This behaviour has been the downfall of many JavaScript implementations of adaptive imagery, as the original image gets requested before JavaScript can jump in and alter the src property.

Community
  • 1
  • 1
zzzzBov
  • 157,699
  • 47
  • 307
  • 349
2

It'll be loaded, if you want a lazy load try changing the css background attribute to match another URL, will be loaded then

Does "display:none" prevent an image from loading?

Community
  • 1
  • 1
Edorka
  • 1,681
  • 13
  • 22
2

Yes it will still be loaded. The browser will still load the values of any content of a div set to display='none' because it is part of the HTML code.

If you want to avoid loading very large media in the html, you should work with javascript or PHP conditions.

LAL
  • 442
  • 4
  • 12