Funky world of Juha

Bizarre and funky world of Juha

Simple image preloading using jQuery September 9, 2010

Filed under: jQuery — juhq @ 12:43 pm

Preloading images (and why not other contents too) with jQuery is pretty simple and easy.

function preloadImage(url) {
 $("<img />").load().attr("src", url);
}

What this function does, is that it loads given image in the background, so when you want to show the image, user already has it in the browser cache.

Usage of this example function is simple as this:


preloadImage("http://jazzdad.files.wordpress.com/2009/11/koala.jpg");

Advertisements
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s