471,074 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,074 software developers and data experts.

Question about Preloading images

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?
Jul 23 '05 #1
6 1433
michaaal wrote:
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Randy Webb wrote:
michaaal wrote:
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';


Image1.src = ...
^
Otherwise a property would be added to the constructor.
....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.


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
Jul 23 '05 #3
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:

michaaal wrote:
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';

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


True, was a typo.
....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.

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.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4
Randy Webb wrote:
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
Jul 23 '05 #5
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:

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.


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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
Randy Webb wrote:
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:
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.


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
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Brynn | last post: by
22 posts views Thread by Fabian | last post: by
2 posts views Thread by windandwaves | last post: by
40 posts views Thread by Geoff Cox | last post: by
9 posts views Thread by peashoe | last post: by
7 posts views Thread by Keith Hughitt | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.