PDA

View Full Version : How to force reload of swf only when version change?


edwardkoo
04-08-2010, 10:05 AM
Hi,

This html code will force reload always
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

To avoid unnecessary reload is there a way to instruct browser to reload my swf file only when i uploaded a new swf?

julianboolean
04-08-2010, 10:39 AM
I might be wrong, but I don't think there is any way to do that. The only sure-fire way of doing it is to rename the SWF every time you update it, which is a pain. Other than that, you could remove the cached version from the browser's cache before reloading it.

rickywh
04-08-2010, 05:05 PM
I'm not sure if this will work but you can try it out. I'm assuming your application makes request to the server back and forth. You can have each request (or each 5th request, or whatever you want) do a check on your server in a xml file or something similar to check if there is a new version available. If it is determined that a new version is available, save the state of your application, hopefully this won't be too much data for you. Then do a


navigateToURL("urlToUrMainMovie.swf", "_parent");


if you want to save the state of your application and retrieve it after the refresh you'll probably have to come up with a nifty way of temporarily storing the data on your server and when you refresh, perhaps pass in a variable in the urlstring above so the swf file knows there is data to be retrieved.


navigateToURL("urlToUrMainMovie.swf?id=get_data", "_parent");


Of course you would have to come up with logic on how to handle the above scenario as well as fail safe mechanism + the deletion of the state data once it's retrieved. navigateToURL() method (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#navigateToURL()) also has security restrictions so I believe it doesn't work in all scenarios, only ones where you have scriptaccess set in your html that contains your swf

edwardkoo
04-11-2010, 12:43 AM
Hi, thanks for the suggestions.

I think what julian suggested is probably the most simple way. I'll just name my swf file as mygamev1.swf and so on...

ricky your suggested method means the user will have to download the swf once if it is old and twice if it is new, and seems to be a bit complicated.
Good blog you have there.

CyanBlue
04-11-2010, 01:22 AM
Howdy and Welcome... ;)

I'd do the same, but do that in HTML level instead to rename the file... I mean, leave the file name as mygame.swf as is, but throw in a variable at the end like mygame.swf?v=1.0 or mygame.swf?v=1.1 to get the job done...

edwardkoo
04-12-2010, 07:30 AM
Oh Cyan, that's better. Thanks!