Load Image from javascript

you can just append another hidden img element and swap them in onload event.

Or use single image element and use javascript like:

var _img = document.getElementById('id1');
var newImg = new Image;
newImg.onload = function() {
    _img.src = this.src;
newImg.src = 'http://whatever';

this code should preload the image and show it when it’s ready

Leave a Comment