How to force Internet Explorer to ignore the cache and reload a SWF...

Dave of davewhite.net and I have just put the finishing touches to a very* simple voting form on a website I have been developing. Users can vote from six choices and the results get picked up by a SWF file that displays the results as an animated bar graph.

The problem, as ever, was Internet Explorer. After casting your vote you would be redirected to a new page containing the SWF file showing the new vote standings (including your vote). This worked fine in Firefox and Safari but, for reasons best known to some useless Microsoft techy, IE saw fit to just load in the SWF with the old data. I tried all sorts of work arounds including meta-tags that (supposedly) prevent IE from caching the webpage but to no avail.

In the end I created a new SWF file, the same shape and size that loads the original one in using the following code:

theDate = new Date();
// this number will always be unique
nocache = theDate .getTime();
_root.holder.loadMovie("myMovie.swf?nocache="+nocache);

The random number *should* prevent IE from just loading in the previous version from cache. Some testing will tell...

Oh - and you can do the same if you are loading in other files, such as txt, too.

* No really - VERY simple.