Computer Magic Logo
Preload images

Friday, January 22, 2016

Published by Aristotelis Pitaridis

Sometimes it is very important to preload all the images so that the user will not wait when he makes an action which requires an image to be displayed.

function PreloadImages(Images) {
    $(Images).each(function(){
        $('<img/>')[0].src = this;
    });
}

PreloadImages([
    '/images/FirstImage.png',
    '/images/SecondImage.png',
    '/images/ThirdImage.png'
]);