Question about Preloading images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • michaaal

    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=Ima ge1.src

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


  • Randy Webb

    #2
    Re: Question about Preloading images

    michaaal wrote:
    [color=blue]
    > Is this the correct way to preload an image...?
    >
    > Var Image1 = new Image()[/color]

    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';
    [color=blue]
    > ....And then when I'm ready to use the image I can do this...?
    >
    > Button1.src=Ima ge1.src
    >
    > ....Or am I just telling Button1 to use the same source path as Image1?[/color]

    With the above additions, now you can.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Question about Preloading images

      Randy Webb wrote:
      [color=blue]
      > michaaal wrote:[color=green]
      >> Is this the correct way to preload an image...?
      >>
      >> Var Image1 = new Image()[/color]
      >
      > 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';[/color]

      Image1.src = ...
      ^
      Otherwise a property would be added to the constructor.
      [color=blue][color=green]
      >> ....And then when I'm ready to use the image I can do this...?
      >>
      >> Button1.src=Ima ge1.src
      >>
      >> ....Or am I just telling Button1 to use the same source path as Image1?[/color]
      >
      > With the above additions, now you can.[/color]

      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

      Comment

      • Randy Webb

        #4
        Re: Question about Preloading images

        Thomas 'PointedEars' Lahn wrote:
        [color=blue]
        > Randy Webb wrote:
        >
        >[color=green]
        >>michaaal wrote:
        >>[color=darkred]
        >>>Is this the correct way to preload an image...?
        >>>
        >>>Var Image1 = new Image()[/color]
        >>
        >>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='ur l to Image';[/color]
        >
        >
        > Image1.src = ...
        > ^
        > Otherwise a property would be added to the constructor.
        >[/color]

        True, was a typo.
        [color=blue][color=green][color=darkred]
        >>>....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?[/color]
        >>
        >>With the above additions, now you can.[/color]
        >
        >
        > 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>[/color]

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

        <img src="theImage.j pg" 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.javas cript FAQ - http://jibbering.com/faq

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Question about Preloading images

          Randy Webb wrote:
          [color=blue]
          > If you want a non-script way of loading images:
          >
          > <img src="theImage.j pg" width="1" height="1" alt="">[/color]

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


          PointedEars

          Comment

          • Randy Webb

            #6
            Re: Question about Preloading images

            Thomas 'PointedEars' Lahn wrote:[color=blue]
            > Randy Webb wrote:
            >
            >[color=green]
            >>If you want a non-script way of loading images:
            >>
            >><img src="theImage.j pg" width="1" height="1" alt="">[/color]
            >
            >
            > That may be viable for graphical browsers,
            > not for other types of user agents.[/color]

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

            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Question about Preloading images

              Randy Webb wrote:
              [color=blue]
              > Thomas 'PointedEars' Lahn wrote:[color=green]
              >> Randy Webb wrote:[color=darkred]
              >>> If you want a non-script way of loading images:
              >>>
              >>> <img src="theImage.j pg" width="1" height="1" alt="">[/color]
              >>
              >> That may be viable for graphical browsers,
              >> not for other types of user agents.[/color]
              >
              > And why would you need to preload/cache images in a non-graphical user
              > agent?[/color]

              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

              Comment

              Working...