0

Simple question.

If I loop through PHP and create several images set to display:none and then use Jquery to access their visibility, does this increase page load time and such as if the images were actually displayed on the page?

If so, is there a simple way to load images dynamically, say if a user selects and option and another image gallery appears but the page does not refresh (ajax?)

Thanks!

1
  • Simple answer: yes. You might check here Commented Jul 20, 2011 at 21:35

2 Answers 2

4

Nope. This will actually take longer since you have to set display:none and then show them with jQuery than if you just showed them as they were downloaded.

In the second part of your question I think you're referring to lazy loading, where the images are loaded on demand from the user, instead of all up front.

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

1 Comment

Just a quick note: showing them with jQuery is only a tiny bit slower - the DOM access times have to be taken into account, but your answer is still technically true ;-) Although I wouldn't recommend pre-loading; as you say, citizen, lazy loading is much better.
1

Yes they would still download and slow things down even with visibility set to none (test it with livehttpheaders [or related] and see).

And yes, you can load them dynamically upon request with jquery in a number of ways. Have an onclick set the src, use an iframe, or create the element from an ajax call etc, etc.

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.