Image Cache

Discussion in 'Javascript' started by jubes, Jan 7, 2004.

  1. jubes

    jubes Guest

    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.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.innerHTML = '<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.innerHTML = '<img src=""
    onerror="func(this)" 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
     
    jubes, Jan 7, 2004
    #1
    1. Advertising

  2. jubes

    Jim Ley Guest

    On 7 Jan 2004 08:42:29 -0800, (jubes) wrote:

    >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.src) and there is no HTTP request back to the server.


    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.

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


    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.javascript FAQ - http://jibbering.com/faq/
     
    Jim Ley, Jan 7, 2004
    #2
    1. Advertising

  3. jubes wrote:

    > 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.src) and there is no HTTP request back to the server.


    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 idOrNameOfElement.src but use
    document.images["idOrNameOfElement"].src. And you better test
    if document.images["idOrNameOfElement"] exists before you do
    that. (You should do this with idOrNameOfElement as reference,
    too.)


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Nokes

    Cache::Cache Stale Segments

    Jeff Nokes, Sep 30, 2003, in forum: Perl
    Replies:
    0
    Views:
    580
    Jeff Nokes
    Sep 30, 2003
  2. DesignerX

    Page.Cache vs HttpContext.Current.Cache

    DesignerX, Jan 20, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    8,260
    vMike
    Jan 20, 2004
  3. =?Utf-8?B?b25l?=
    Replies:
    1
    Views:
    5,295
    Karl Seguin [MVP]
    Mar 8, 2006
  4. Sergey via DotNetMonster.com

    ASP.NET Cache vs Window System Cache

    Sergey via DotNetMonster.com, Nov 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    481
    Sergey via DotNetMonster.com
    Nov 15, 2006
  5. Jake Barnes
    Replies:
    7
    Views:
    199
    Evertjan.
    Dec 8, 2005
Loading...

Share This Page