getButterfly Logo getButterfly

Preloading images with jQuery

Preloading images with jQuery, option 1. Just putting this out there.

$(document).ready(function() {
   // preload images // create image array
   var pics = [];

   // preload images // main function
   function preload() {
      for(i = 0; i < arguments.length; i++) {
      pics[i] = new Image();
      pics[i].src = arguments[i];

// preload images // do it!

Preloading images with jQuery, option 2.

// preload images // main function
function preloadImage(url) {
   var img = new Image();
   img.src = url;

// preload images // do it!

Photo credit: pwkpwkpwk.

Subscribe to getButterfly Blog

Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.

If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.

Leave a Reply

Your email address will not be published. Required fields are marked *