简体   繁体   中英

preloading images with jquery - does the image stay in cache?

so I have a general question about preloading. I am using a few large images as sprites to be appended in various places throughout my mobile site, but because they are background images (assigned on the fly when jquery assigns certain class names to divs) - I'm not sure how best to preload these.

I saw this post here:

http://jquery-howto.blogspot.com/2009/02/preload-images-with-jquery.html

where you simply do this:

var image1 = $('<img />').attr('src', 'imageURL.jpg');

but if I preload images in this manner, and then never directly assign them to a dom element (because they will be assigned as a background image with a css class) - is preloading these images doing me any good?

It should still help as long as your script runs at the end and not in the middle of DOM rendering (As that'll block the page). You won't see the flickr effect when they get assigned.

The image will be picked up from the cache as long as the image URL doesn't change.

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