Image Cache

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

    Image Cache

    Hi,

    I've been developing an intranet application that uses IE 5.5 and have
    come across a problem, well sort of.

    Since the application uses frames I use an array of Image objects to
    cache the image in the top frame. Now replacing an exsiting the image
    source on an existing image tag is easy (ie imgTag.src =
    imgArry[i].src) and there is no HTTP request back to the server.

    Now expanding that concept further if I create an image tag with
    javascript by using divTag.innerHTM L = '<img src="imgURL">' this
    created tag will make an HTTP request to the server, and since I've
    all ready cached all images the server returns a 304 (not modified)
    and does not return image data.

    So to avoid the HTTP request I tried divTag.innerHTM L = '<img src=""
    onerror="func(t his)" imgIndex="1">'

    where

    function func(ref){
    ref.src =imgArry[ref.imgIndex].src];
    }

    therefore in this case we have an existing image tag, albeit it throws
    an error, and do the normal image replace. now in this scenerio it
    still makes a HTTP request.

    Why does the last scenario make a HTTP request? Also is there a way to
    create an image tag on the fly without it making a HTTP request?

    thanks
  • Jim Ley

    #2
    Re: Image Cache

    On 7 Jan 2004 08:42:29 -0800, josiah.wong@jpm organ.com (jubes) wrote:
    [color=blue]
    >Since the application uses frames I use an array of Image objects to
    >cache the image in the top frame. Now replacing an exsiting the image
    >source on an existing image tag is easy (ie imgTag.src =
    >imgArry[i].src) and there is no HTTP request back to the server.[/color]

    That would all depend on the cache settings, if the above doesn't make
    an http request, then I'm surprised an innerHTML call does, I've
    never seen where the 2 are not absolutely equivalent.
    [color=blue]
    >Why does the last scenario make a HTTP request? Also is there a way to
    > create an image tag on the fly without it making a HTTP request?[/color]

    Nope, but IE fully honours cache settings, and you really should not
    have got this far without visiting htt://www.mnot.net/cache_docs/ do
    so now, and your problems will go away.

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

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Image Cache

      jubes wrote:
      [color=blue]
      > Since the application uses frames I use an array of Image objects to
      > cache the image in the top frame. Now replacing an exsiting the image
      > source on an existing image tag is easy (ie imgTag.src =
      > imgArry[i].src) and there is no HTTP request back to the server.[/color]

      No matter if it's only IE, do it the standards-compliant way
      wherever you can (and you can here, without breaking functionality
      but with cleaning up the namespace). You may want to port it
      sometime. So do not use idOrNameOfEleme nt.src but use
      document.images["idOrNameOfElem ent"].src. And you better test
      if document.images["idOrNameOfElem ent"] exists before you do
      that. (You should do this with idOrNameOfEleme nt as reference,
      too.)


      PointedEars

      Comment

      Working...