Wednesday, March 28, 2012

Prefetching Images

I am using the update panel, and the timer control to automatically change a person's profile text, and their photo (small 65x65 pixels). Everything works well so far, except the transition is not always smooth for the photo.

Before the images/photos become cached in the browser, the default broken (link-to-image) image shows up, before the relevant photo loads. After that image loads the first time, the transition is smooth.

Is there a way to prefetch these images (approximately 8) when the page loads?

Thanks,

Karls

The easiest way I know of is to create a .js function to preload the images. Something like:

function preload(){
var imageUrls = ["img1.jpg","img2.jpg","img3.jpg"];
var images = [];
for(var i=0;i<imageUrls.length;i++){
var image = new Image();
image.src = imageUrls[i];
images.push(image);
}
}

That you'd call that function during pageLoad(). Setting the 'src' of the image object should cause the browser to start downloading that image.


Nice,

I would like to try that, but I am having a problem converting this to VB. Can anyone convert this?Huh?


No, i'ts javascript.


Ahh, makes sense now.

Thanks.

No comments:

Post a Comment