Javascript preload images script


This post teaches you the proper efficient way to preload images with javascript.

if (document.images)
preload_image = new Image();
img_path = new Array();

img_path[0] = “”;
img_path[1] = “”;
img_path[2] = “”;
img_path[3] = “”;
img_path[4] = “”;

for(var i = 0; i<=img_path.length; i++)
preload_image.src = img_path[i];

All you need to do is add more img_path[x] = “”; line for each image to preload. This is very usual when using CSS text links with background images.

Article written by developer and designer


If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.

Leave a Comment