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 appende开发者_如何转开发d 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.
精彩评论