With the help of Google I've written a small preloader script:
var i = 0;
function preloader() {
imageObj = new Image();
images = [
'some/image1.jpg',
'some/image2.jpg',
'some/image3.png',
'and.png',
'so.jpg',
'on.png'
];
for (i = 0; i <= 20; i ++) {
imageObj.src = images[i];
}
}
This function must be called in the head
of my HTML file for maximum effect, right? Do I really need to declare var i = 0;
? How can I fire another function once the preloading is complete?
Also, I would like to ask how to implement this function in running websites. Let's say I have a page that has 100 img
tags. I guess I have to copy and paste the source into the images
array by hand, right? Because to do that with a loop, the DOM needs to be ready which again means that the images have already started loading?
Does preloading affect SEO?
If there is a better jQuery way of preloading I would be ok with that.