Hello there,
I use javascript to preload images as show below. The problem is that every time a page is refreshed, it preloads again. Is there any way to get an image into memory that stays there forever without any more preloading?
<script type='text/javascript'>
if (document.images) {
img001 = new Image(); img001.src = 'images/background.jpg ';
img002 = new Image(); img002.src = 'images/banner.jpg ';
}
</script>
Preloaded Images
Moderator: General Moderators
Re: Preloaded Images
The "complete" property:
complete Property
The complete property is read-only and returns a Boolean value indicating whether or not the browser has completed loading the image.
Syntax: Image.complete
complete Property
The complete property is read-only and returns a Boolean value indicating whether or not the browser has completed loading the image.
Syntax: Image.complete
Code: Select all
if(img001.complete == false) {
img001.src = 'images/background.jpg';
}
Re: Preloaded Images
no, but if response headers are correct, then they will be saved in browsers cachem, but it's fastto get an image into memory
Are you sure it preloads from server and not from cache? How did you checked it?The problem is that every time a page is refreshed, it preloads again
Sorry, but Reviresco solution won't work, because there's nothing to preload, see
Code: Select all
img001 = new Image(); //Creates blank image
if(img001.complete == false) { //Image doesn't have src, so it's true and 'images/background.jpg' won't be preloaded