Inserting an <img src="X"> into the DOM with javascript under IE ignores image cache

Discussion in 'Javascript' started by Todd, Jul 24, 2003.

  1. Todd

    Todd Guest

    Please help!

    Under IE6, I'm dynamically modifying my page with some javascript
    which inserts some elements into the page's DOM.

    For example:

    function RenderNewLayerSyms (destEl, controlNumber) {
    for (var i=0; i<5; i++) {
    var empty = document.createElement ('img');
    empty.src = VirtualAppRoot + 'images/rbsempty.gif';
    empty.id = 'rr_' + controlNumber + '_sym_' + (i + 1);
    empty.alt = 'Rate this DVD ' + (i + 1) + ' out of 5';
    empty.onmouseover = NewRRMouseOver;
    empty.onclick = NewRRClick;
    destEl.appendChild (empty);
    }
    }

    It all works fine, but when I insert an image tag, say

    <img src='images/rbsempty.gif'>

    into the page, the browser requests a new copy of X.gif from the web
    server *every* time. This is a problem becuase I'm inserting 100+ of
    these tags dynamically - and making 100+ requests to get the same
    image over and over. Why isn't it caching?

    Thanks,
    Todd.
     
    Todd, Jul 24, 2003
    #1
    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.