I had some good comments on my post about the lack of a “no cache” feature in Flash/Central, but there was some confusion about why this feature is necessary..    and most people seemed to accept that preventing caching of SWFs delivered via the web to the Flash Player is impossible. so.. I dug back through my old files.

First you need to accept a few things:

  1. It’s easy to use an application other than a web browser to request files from a web server, and so your efforts to instruct the browser to not cache the file can be circumvented.
  2. Some browsers will ignore your instructions to not cache the files.. FireFox is one that will cache SWFs no matter what I try.
  3.  
  4. Your efforts will only prevent the "honest" people from getting your   SWF. Someone who is determined WILL get your SWF.

If you’re still reading then I’ll assume you just want to make it a little harder for someone to get your SWF, and you realize that at best you’re going to stop 80 or 90% of the people from getting that precious SWF.

Still interested? Then try this..

  1. check your browser cache. On Windows XP using Internet Explorer it is typically located here:
    C:Documents and Settings%your username%Local SettingsTemporary Internet Files
    Mozilla is typically something like:
    C:Documents and Settings%your username%Application DataMozillaFirefoxProfilesdefault.8wqCache
  2. Sort the contents of that folder by "Last Accessed" so you can see the most recently accessed files at the top.
  3. Now click this link to open a new browser window: http://www.oddhammer.com/tutorials/nocache/SWF_security.html
  4. And now refresh your browser cache folder and you should not see the SWF_security.html file, a GIF, and a couple of SWF files listed in there. If you do see them, then count yourself in the 10% (just a guess..) who are going to cache the files despite my best efforts. I already know that Firefox does not cache the HTML or GIF files, but it does cache the SWF files.. I just don’t know why.

If you didn’t see the files in your cache then you might be wondering how I did that..

In my httpd.conf file (for Apache) I added this:

ExpiresActive On
header append cache-control: "no-cache"
header append pragma: "no-cache"
header append expires: "-1"

for the folder.. so everything I place in that folder will be sent with the HTTP headers instructing the browser to not cache it.
From what I’ve found on the web those directives _should_ instruct Mozilla/FireFox to NOT cache the HTML, GIF, or SWFs… but it still caches the SWFs.
There are similar "per folder" settings for IIS.

You can also set the headers in HTML, ASP, PHP, etc.. via Meta tags and there’s info here: http://www.htmlgoodies.com/beyond/nocache.html but I think that only applies to the page itself, and does not apply to all the subsequent SWFs loaded from a "parent" SWF. So if my SWF loads other SWFs then simply putting the nocache directives in the HTML file will not prevent those additional SWFs from being cached (at least that’s what I’ve found..).


You can also read the technote from Macromedia (last updated Sept of 2000) here: http://www.macromedia.com/support/flash/ts/documents/prevent_caching.htm but it uses the Meta tag route.


Also, some folks are only interested in forcing the browser to always load the latest version of a SWF by adding a random number to the end of the URL.. and others try to prevent caching of audio files and images by sending them through a Flash Communication server (that’s pretty extreme..). Different needs require different solutions.


Now.. back to my original rant..err point.. these solutions are merely workarounds. I shouldn’t have to make changes to my server, or rely on Meta tags in the HTML file, or have to send images through the FlashComm server… I should be able to tell the Flash Player to load a SWF or an audio file and NOT cache the file.