Hello,

I am using a jQuery script to insert iframe in the document after the
page load completes as follows:

jQuery(window).load(function() {
    var container = jQuery(‘#container_id”);
    jQuery(‘<iframe id=”my_iframe”
src=”www.some-url.com”></iframe>’).prependTo(container);
});

Apparently there is a problem (or probably a speed-up trick) with
Firefox where it tries to cache any iframe content so that next time
when you come back to the page (using forward or back button), it
fetches the content of the iframe from its cache rather than making a
new request. This is a problem to my usecase as the number of request
received by the server is of high importance.

Hence to get around this caching issue I have a small piece of
cache-busting code just after prependTo() call above, which forces a
reload of the iframe is as follows:

if ((navigator.userAgent.indexOf("Firefox") > -1) &&
(navigator.userAgent.indexOf("Windows") > -1)) {
    var i = document.getElementById("my_iframe");
    if (i) {
        i.src="www.some-url.com";
    }
}

I read somewhere that when we add iframes to the DOM dynamically, it
actually takes some amount of time before which it can be queried
using the standard DOM manipulation function. So, I am suspecting that
for most of the time my cache-busting code above does not do anything,
but it’s hard to spot the error as it could be happening only 1 in 10
times or less.

My question is, would using jQuery’s selector to get the iframe node
for cache-busting help me get around this iframe-ready-to-query delay?
I just want to ensure that my cache-busting code runs every time its
meant to run.

I appreciate any help.

Thanks,

Reply via email to