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?

3

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.