I just recently noticed that when you click an image on Yahoo! Image Search it first shows a low resolution image which then gradually turns into a high resolution image.
Example: Yahoo! Image Search
When you click the link above and click through all the images you notice that they're always showing a low resolution image first. Why are they doing it? Does the website appear to be loading faster to the user if they're doing it this way?
Also, could someone please point me into the direction on how this is actually done (preferably by using JQuery, in the case that they're using JavaScript to do it)?
They're using a cache of thumbnails from this URL
where
HASHandNUMare (somehow) references to a particular thumbnail.For example,
NUM = 1148286928700andHASH = d2f4bbf91a853cefbc18794b6eb9ecddare a reference to this thumbnail.Of course, thumbnails are smaller in file size than bigger images, so Yahoo! loads from a cache of thumbnails first to give the user a glimpse of what the image is, and loads the full size image in the background.
I suspect the technique they use is load the image in to a hidden
imgtag, and then bind to theloadevent of that image tag to a function which replaces the thumbnailsrcwith the full size imagesrc. Hence, when the (hidden) full size image is loaded, it replaces the thumbnail image we see on page load.Let's assume the thumbnail image is loaded in to an
imgtag with an ID ofmain_image, and our full size image is loading (in the background) in a hiddenimgtag with an ID ofsecondary_image. Then we bind to theloadevent of#secondary_image, and replace thesrcof#main_imageon load:Then when the user wishes to view another image, we replace the
srcof#main_imagewith a different cached thumbnail, replace thesrcof#secondary_imagewith the large image, and bind theloadevent again (so ideally you'd create a function with the above code, and call this function whenever you changed the#secondary_imagesrc.