Return to Snippet

Revision: 9504
at November 10, 2008 22:34 by nighthawk


Updated Code
// preloading function of images
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
};

// use like
$.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");

Revision: 9503
at November 10, 2008 18:49 by nighthawk


Updated Code
// preloading function of images
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// use like
$.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");

Revision: 9502
at November 10, 2008 18:45 by nighthawk


Initial Code
// preloading function of images
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// use like
$.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");

// preloading function for arbitrary content (which usually contains images)
jQuery.preloadContent = function(){
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<div>").html(arguments[i]);
  }
}

// use like (myvar being a JS variable with content to preload)
$.preloadContent(myvar1, myvar2);

Initial URL
http://www.innovatingtomorrow.net/2008/04/30/preloading-content-jquery

Initial Description
Thanks to Matt Farina

Also see similar snippet for preloading arbitrary content, e.g. media in content received via AJAX.

Initial Title
jQuery preloading images

Initial Tags
javascript, jquery

Initial Language
JavaScript