Fix Flash SWF Caching
Anyone who has worked with a client knows that when the project launches, the work is never over. Often after launch you are prompted with a list of changes the client requests. In another case, you may have missed a large bug that hinders the user’s experience. In either case, you are left with a common problem when you are ready to push your new changes live: Flash Caching. By default a user’s browser will cache your swf files, rendering the user unable to see the new changes you just pushed. It is almost always a guarantee that that “user” is in fact your client on the other end of the phone telling you in a heated tone “NO, I still do not see the changes”. I have found the common tactic of tacking on random URL parameters to the swf’s location doesn’t always work for those in IE. It seems the browser often ignores the extra parameters when decided to load the new swf file or pull it from cache.
To fix this problem once and for all, I have been using a similar method. Instead of tacking on parameters to the URL, I include version numbers in the actual file name. This will ensure the browser will reload the new file. I embed my “shell_v1.swf” in the HTML and pass it a variable called “app_location” with a value of “myApp_v1.swf”. “app_location” is the URL path to to my actual app swf. The shell then loads the app and displays it. The app swf should also be labeled by version to ensure it will be reloaded with new versions. This should be easy for users programming in AS3, since you will most likely have your preloader in a separate swf.

Oh yeah, these project launches are usually pain in the a$$. I decided not to name the files filename_1, filename_2, filename_3 etc. but to copy the whole system to a new folder folder-1/, folder-2/, folder-3/ etc. It allows also to roll back if the client doesn’t want something from the new version.
Hi,
Can you please put a sample file for this or please explain step by step. Do you mean loading a swf file from the embedded swf in html?
shine,
Yes, in my example above I describe the process of embedding a “shell” swf in the HTML and passing that swf file a variable of the “app” location. Personally I use swfObject to embed the shell swf file. It’s painless and easy to pass in variables.
For more information about embedding using swfObject, go here:
http://code.google.com/p/swfobject/wiki/documentation
Here is a trick I learned years ago for AS2 and just tested in AS3. It works great.
Mind you it doesn’t work offline but all you do is add the code before you go live.
Change this –> l.load(new URLRequest(“your_file.swf”));
To this –> l.load(new URLRequest(“your_file.swf?ver=” + Math.floor(Math.random() * 999)));
With this code it never loads from the cache unless by some magical chance the random number is the same as the cache version
I just use nocache by default and a GUID class i found on line:
var nocacheKey:String = “?nocache=” + GUID.create();
var urlLoader……
urlLoader.load(fileToLoad+nocacheKey);