Preloading Image

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

    #1

    Preloading Image

    Hi. I have one image that has to show up in a html page several times.
    To save time, I'd like to preload this image. As an example:

    if (document.image s) {
    tester = new Image()
    tester.onload=f unction() {cImg('good')}
    tester.onerror= function() {cImg('bad')}
    tester.src="ima ge.jpg"
    }
    function cImg(typ) {
    if (typ == 'bad') {alert('bad image') ; return}
    document.images .main.src = tester.src
    }


    Problem, at least on my local html copy. When my IE6 loads the image,
    tester.src changes from "image.jpg" to
    "file:///C:/Inetpub/wwwroot/mas/image.jpg". document.images .main.src =
    tester.src", therefore, doesn't work. Question. After my onload, if I
    did document.images .main.src = "image.jpg" , wouldn't another copy of
    "image.jpg" have to load?

    I was thinking. Couldn't I set the object document.images .main to the
    object tester? If so, how?

    This may be no big deal, but I'd like my offline copy of my web site to
    work like my online copy...Dennis


  • Jim Ley

    #2
    Re: Preloading Image

    On Sun, 20 Mar 2005 15:26:44 -0500, "Dennis Allen"
    <dennis@dennisa llen.com> wrote:
    [color=blue]
    > After my onload, if I
    >did document.images .main.src = "image.jpg" , wouldn't another copy of
    >"image.jpg" have to load?[/color]

    No, that isn't how preloading works, it's all about URI's it's got
    nothing to do with what you put in the document, if the URI's the same
    then the browser _may_ cache it.

    Browsers rarely cache file:// resources not surprisingly...

    Jim.

    Comment

    • nobody@nowhere.com

      #3
      Re: Preloading Image


      To do my good deed as someone gave me a hand with some problem I had:

      What you are implying is caching of the image and it depends on the
      settings of the browser whether it will cache an image or download it
      every single time.

      If the settings of the browser lean toward using cached objects rather
      than downloading everything, then so long as you give the exactly the
      same location of the object, the browser will use the cached object.

      Preloading objects is all about getting objects ready for event
      processing (i.e. changing an image on a mouse over) where speed is of
      the essence. But I suppose you could use it to force caching.

      I wouldn't trust testing locally as your browser will sense that you
      are local and won't cache!

      Paul



      On Sun, 20 Mar 2005 15:26:44 -0500, "Dennis Allen"
      <dennis@dennisa llen.com> wrote:
      [color=blue]
      >Hi. I have one image that has to show up in a html page several times.
      >To save time, I'd like to preload this image. As an example:
      >
      >if (document.image s) {
      > tester = new Image()
      > tester.onload=f unction() {cImg('good')}
      > tester.onerror= function() {cImg('bad')}
      > tester.src="ima ge.jpg"
      >}
      >function cImg(typ) {
      > if (typ == 'bad') {alert('bad image') ; return}
      > document.images .main.src = tester.src
      >}
      >
      >
      >Problem, at least on my local html copy. When my IE6 loads the image,
      >tester.src changes from "image.jpg" to
      >"file:///C:/Inetpub/wwwroot/mas/image.jpg". document.images .main.src =
      >tester.src", therefore, doesn't work. Question. After my onload, if I
      >did document.images .main.src = "image.jpg" , wouldn't another copy of
      >"image.jpg" have to load?
      >
      >I was thinking. Couldn't I set the object document.images .main to the
      >object tester? If so, how?
      >
      >This may be no big deal, but I'd like my offline copy of my web site to
      >work like my online copy...Dennis
      >[/color]

      Comment

      • Dennis Allen

        #4
        Re: Preloading Image

        "Jim Ley" <jim@jibbering. com> wrote in message
        news:423ddee0.2 41183473@news.i ndividual.net.. .[color=blue]
        > On Sun, 20 Mar 2005 15:26:44 -0500, "Dennis Allen"
        > <dennis@dennisa llen.com> wrote:
        >[color=green]
        >> After my onload, if I
        >>did document.images .main.src = "image.jpg" , wouldn't another copy of
        >>"image.jpg" have to load?[/color]
        >
        > No, that isn't how preloading works, it's all about URI's it's got
        > nothing to do with what you put in the document, if the URI's the same
        > then the browser _may_ cache it.
        >
        > Browsers rarely cache file:// resources not surprisingly...[/color]

        Every preload example I've seen goes src = src. Just checked my old
        Windows 98 machine. It has IE6 which also adds "file://" to tester.src.
        Is it possible to set the <img> object with the Image() object?


        Comment

        • Jim Ley

          #5
          Re: Preloading Image

          On Mon, 21 Mar 2005 00:01:26 -0500, "Dennis Allen"
          <dennis@dennisa llen.com> wrote:
          [color=blue]
          >"Jim Ley" <jim@jibbering. com> wrote in message[color=green]
          >> No, that isn't how preloading works, it's all about URI's it's got
          >> nothing to do with what you put in the document, if the URI's the same
          >> then the browser _may_ cache it.
          >>
          >> Browsers rarely cache file:// resources not surprisingly...[/color]
          >
          >Every preload example I've seen goes src = src. Just checked my old
          >Windows 98 machine. It has IE6 which also adds "file://" to tester.src.
          >Is it possible to set the <img> object with the Image() object?[/color]

          No, there's no such thing as an image object with any actual image
          information in it, and it's completely irrelevant to the ability to
          cache it.

          I can't think off hand a of a browser that does not expand the url to
          the full one in img.src

          Jim.

          Comment

          Working...