简体   繁体   中英

Php Jquery Javascript preloading images

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM