Question about Preloading images

M

michaaal

Is this the correct way to preload an image...?

Var Image1 = new Image()

....And then when I'm ready to use the image I can do this...?

Button1.src=Image1.src

....Or am I just telling Button1 to use the same source path as Image1?
 
R

Randy Webb

michaaal said:
Is this the correct way to preload an image...?

Var Image1 = new Image()

var is case sensitive, its lower-case v

And you have forgotten to define the src attribute to the new Image()
you just created.

Image.src='url to Image';
....And then when I'm ready to use the image I can do this...?

Button1.src=Image1.src

....Or am I just telling Button1 to use the same source path as Image1?

With the above additions, now you can.
 
T

Thomas 'PointedEars' Lahn

Randy said:
var is case sensitive, its lower-case v

And you have forgotten to define the src attribute to the new Image()
you just created.

Image.src='url to Image';

Image1.src = ...
^
Otherwise a property would be added to the constructor.
With the above additions, now you can.

Yes, indeed :)

Yet it is not a very good way of preloading images, if there is some
(preloading should be done very careful -- not only that is is not really
required, it is unreliable [because my cache is *my* cache and client-side
scripting may be disabled/restricted/not present] and if it works it forces
users to download data they do not requested), it is unreliable,
error-prone and quite hard to maintain. I have been working on another
approach that does not show most of these problems:

<http://pointedears.de/scripts/test/hoverMe>


PointedEars
 
R

Randy Webb

Thomas said:
Randy Webb wrote:




Image1.src = ...
^
Otherwise a property would be added to the constructor.

True, was a typo.
With the above additions, now you can.


Yes, indeed :)

Yet it is not a very good way of preloading images, if there is some
(preloading should be done very careful -- not only that is is not really
required, it is unreliable [because my cache is *my* cache and client-side
scripting may be disabled/restricted/not present] and if it works it forces
users to download data they do not requested), it is unreliable,
error-prone and quite hard to maintain. I have been working on another
approach that does not show most of these problems:

<http://pointedears.de/scripts/test/hoverMe>

If you want a non-script way of loading images:

<img src="theImage.jpg" width="1" height="1" alt="">

And its a 1 pixel dot on the page, but the image gets loaded, unless
images are disabled and then it doesn't really matter.
 
T

Thomas 'PointedEars' Lahn

Randy said:
If you want a non-script way of loading images:

<img src="theImage.jpg" width="1" height="1" alt="">

That may be viable for graphical browsers,
not for other types of user agents.


PointedEars
 
R

Randy Webb

Thomas said:
Randy Webb wrote:




That may be viable for graphical browsers,
not for other types of user agents.

And why would you need to preload/cache images in a non-graphical user
agent?
 
T

Thomas 'PointedEars' Lahn

Randy said:
And why would you need to preload/cache images in a non-graphical user
agent?

You would not but the display of those "img" elements intended merely for
preloading/caching could be disturbing anyway. Text browsers like lynx
or links, e.g., can be configured to display "img" elements as a link for
downloading the image resource as a file (to be displayed by user-defined
graphics viewer software, for example).


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top