View Single Post
Old 12-11-2012, 05:36 PM   PM User | #36
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I might consider pre-loading just a few images at the beginning (script in the head tag) and, after the page has loaded, continue loading/caching the remaining images.
Code:
var myImgs = ['path/to/img1.jpg', 'path/to/img2.gif'];
var x = 0, y = 5;
function preload(imgs, x, y) {
    var img;
    for (var i = x; i < y; ++i) {
        img = new Image(); // if you know the size of the images (and they are the same) use Image(200, 300);
        img.src = imgs[i];
    }
}
preload(myImgs, x, y);
window.onload = function () {
    // or just put this code before the closing body tag
    preload(myImgs, y+1, myImgs.length);
}
In terms of a tutorial, I would just be Googling for one, but perhaps someone else has a recommendation.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote