apamphilon

Preload Images Using JavaScript

function preloadImages() {
    var buffer, images;

    buffer = new Image();
    images = document.getElementsByTagName('img');

    if (images.length) {
        for (var i = 0, l = images.length; i < l; i++) {
            var image = images[i];
            buffer.src = image.src;
            $(image).attr('src', buffer.src);
        }
    }
}

//init
preloadImages();

Credit: Written by Matt Royce


Comments: