Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Scripts

Reply
 
LinkBack Thread Tools Display Modes
Old 09-24-2011, 09:41 AM   #1
New Member
 
Join Date: Nov 2010
Posts: 8
Default Preload images with Javascript

Hi!

I've just started experimenting with preloading of images with Javascript to speed up things, by loading new Image objects and setting the src to images likely to be needed in the future.
My question is, do you need to attach the object to a variable, or can you save memory by just apply them "on the fly"?

E.g. on the first page of www.metropolisonline.org I have 4 clickable screenshots from the game (i.e., only thumbnails on the first page).
Then, in the body onload, I create an array of 4 new Image objects and set the them to the screenshots e.g.
Code:
a[0].src = 'images/screenshot1.png';
This way all images are hopefully loaded if the user clicks on the thumbnails.
I'm just wondering if I need the array at all? Is it possible to do
Code:
new Image().src='images/screenshot1.png'
on each screenshot?
Iv'e seen similar code on the Google front page, but does it work?
Tarzan is offline   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:42 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.