How to prevent preloaded images from reloading when images are switched?

Question by Confused: How to prevent preloaded images from reloading when images are switched?
Alright, I’m confused and embarrassed about this; preloading images is supposed to be really basic.

Anyway, I’m using the script found at:

http://www.mattfarina.com/2007/02/01/preloading_images_with_jquery

which is a widely used script that is the first thing you see in google when you type in jquery image preload, and it does really preload the images. The problem is that even though the images are preloaded, whenever I switch images using $ (“image”).attr(“src”, “so/and/so.jpg”), it still requests a new image instead of using what’s already preloaded. I hope this is just one of those ‘slap your forehead’ moments and there’s a really simple solution, but for now, I’m stumped.

Now before you go ahead and just suggest another preloading script, please note that I’ve used a ton of other jquery and non-jquery scripts, but all of them seem to have the same effect: images are preloaded, but each request reloads the image regardless of whether it’s been preloaded.

So here’s the question: how do I make sure that if the image has been preloaded, it is not reloaded when it needs to appear on the page?

I’ve tried in all major browsers (Firefox 3.5, IE8, Opera, Safari/Chrome…)

Best answer:

Answer by Ron
Just curious as I have never used JQuery yet. Is it possible the preload paths for the images are different for the same images being switched? Just a guesstimate on this being the problem because preloaded images should have been placed in the browser’s cache unless there appears to be a need to reload because the image path has been changed for the same image.

Gotta try out JQuery one of these days.

Ron

Give your answer to this question below!

About Admin