Firefox Iframe Caching Bug
One of the most frustrating parts of web programming is dealing with browser quirks. Javascript that works in one browser might not work in a different browser on the same OS; better yet, that same Javascript might not even work in the same browser and on different OS. Great, welcome to cross-browser/OS testing hell.
One particularly nasty browser quirk that I recently had to deal with was a Firefox iframe caching bug. You can check out the full 5-year old bug report in all its glory here.
To summarize the problem, if you have an iframe whose content is set dynamically on page load, Firefox will cache the content of the iframe so that on the next page load, it will serve the cached content rather than the new dynamically generated content. Traditional cache-breaking techniques like modifying the HTTP headers or adding a random string to the URL don’t work here.
After wrestling around for a while, I found a few posts here and here that helped me figure out a solution that worked for my case. Here’s the gist of it:
var iframe = document.createElement("iframe");
iframe.src = "http://calvinyoung.org";
document.body.appendChild(iframe);
// And then set the src AGAIN after the iframe's been added
iframe.contentWindow.location.replace(iframe.src);
Why can’t browsers just agree on a uniform standard. It really would make everybody’s life so much easier.
