Question about Preloading images

Discussion in 'Javascript' started by michaaal, Aug 8, 2004.

  1. michaaal

    michaaal Guest

    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...?


    ....Or am I just telling Button1 to use the same source path as Image1?
    michaaal, Aug 8, 2004
    1. Advertisements

  2. michaaal

    Randy Webb Guest

    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';
    With the above additions, now you can.
    Randy Webb, Aug 8, 2004
    1. Advertisements

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


    Thomas 'PointedEars' Lahn, Aug 10, 2004
  4. michaaal

    Randy Webb Guest

    True, was a typo.
    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 Webb, Aug 10, 2004
  5. That may be viable for graphical browsers,
    not for other types of user agents.

    Thomas 'PointedEars' Lahn, Aug 10, 2004
  6. michaaal

    Randy Webb Guest

    And why would you need to preload/cache images in a non-graphical user
    Randy Webb, Aug 10, 2004
  7. 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).

    Thomas 'PointedEars' Lahn, Aug 10, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.