This is actually an old version of danielmall.com. For the latest and greatest, check out the new site.
 

Flash Cache

Having trouble seeing the most current version every time you update a Flash movie? Here’s a quick tip to help you get over that.

I almost always use SWFObject when embedding a Flash file into an HTML page. I often have problems in seeing the most recent versions when I make incremental updates to a SWF.

To eliminate this, I now add a random query string to my file name. So instead of…


swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");

…I’ll do…


swfobject.embedSWF("myContent.swf?" + Math.random(), "myContent", "300", "120", "9.0.0");

It eliminates the caching problem by tricking the browser into looking for a different file without changing the location of your movie. Not an original trick by any means, but I hope it helps someone out there.

Comments

Michael Espinosa said:

Nice little trick, very handy. Thanks.

Posted on July 6, 2008 12:40 PM

Brian Warshaw said:

Yeah, I found the need for this when I was building a Flash MP3 player in Actionscript, though I ended up appending the randomness to the URL that was requesting the playlist. I believe Rails uses the technique for JS and CSS files by default.

Posted on July 10, 2008 04:46 PM

Tory said:

I'll have to keep this in mind for next time... Thanks for the tip.

Posted on July 14, 2008 10:23 PM

David Hemphill said:

Thanks so much for this. A good, simple solution for an annoying problem.

Posted on July 19, 2008 08:29 PM

Aaron said:

Very nice. Where I work we added a Flash piece to the home page and rather than update the name of the SWF each time we can use this technique. Thank you.

Posted on August 6, 2008 12:44 AM

Jack Andrews said:

Daniel, I am a designer in Dallas and an advertising veteran. I am impressed with your site, but even more impressed with your copywriting. Thanks.

Posted on August 27, 2008 10:32 AM

Michael Reiner said:

Immensely useful Dan!
As always, great stuff here.
Thanks!

Posted on August 27, 2008 04:20 PM

Sorry: comments are closed.