tags:

views:

4193

answers:

12

I have a Flex application with multiple modules.

When I redeploy the application I was finding that modules (which are deployed as separate swf files) were being cached in the browser and the new versions weren't being loaded.

So i tried the age old trick of adding ?version=xxx to all the modules when they are loaded. The value xxx is a global parameter which is actually stored in the host html page:

var moduleSection:ModuleLoaderSection;
moduleSection = new ModuleLoaderSection();
moduleSection.visible = false;
moduleSection.moduleName = moduleName + "?version=" + MySite.masterVersion;

In addition I needed to add ?version=xxx to the main .swf that was being loaded. Since this is done by HTML I had to do this by modifying my AC_OETags.js file as below :

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf?mv=" + getMasterVersion(), "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

This is all fine and works great. I just have a hard time believing that Adobe doesn't already have a way to handle this. Given that Flex is being targeted to design modular applications for business I find it especially surprising.

What do other people do? I need to make sure my application reloads correctly even if someone has once per session selected for their 'browser cache checking policy'.

A: 

The caching is not done by Flash Player but by the browser, so it's out of Adobe's control. I think you have found a workable solution. If I want to avoid caching I usually append a random number on the URL.

Theo
right, but finding a workable solution isnt out of their control. primarily i want to make sure i'm not missing some built in feature and reinventing the wheel. i specifically DONT want a random number because I want the application to be cached when possible
Simon_Weaver
A: 

Hi Simon,

Great post! Sorry if I'm slow but got few questions: 1) Where do you declare ModuleLoaderSection? 2) in AC_FL_RunContent(), how do you define the getMasterVersion()? Thanks

a) ModuleLoaderSection is just a wrapper around a module that implements interfaces a 'section' in my application uses. I should have simplified the code to make it more generic.
Simon_Weaver
b) function getMasterVersion() { return "30";} // this function is in my main .aspx page (.NET) for my application. the 30 is incremented for each new version
Simon_Weaver
Tips: be sure your AC_FL_RunContent function never gets overwritten - periodically check to see it hasnt been. Use Fiddler to check the URLs are properly being constructed
Simon_Weaver
A: 

post withdrawn by Clowe

+1  A: 

What I have done is checksum the SWF file and then add that to its url. Stays the same until the file is rebuilt/redeployed. Handled automagically by a few lines of server-side PHP script

Scott Evernden
sounds interesting. i like the 'set and forget' thinking. where are you storing/caching these checksums? you're not recalculating them automagically with every page request are you?
Simon_Weaver
Scott Evernden
.. for the much larger resource SWFs that I also use, I put the computed checksum into a side-file that is written at creation-time. Ajax responses convey checksum-tagged SWF urls to client as needed.
Scott Evernden
Can you please provide a code sample?
John Isaacks
A: 

Hi, Could you please send me the sample code. I am in deperate need of preventing cache problem. I would appreciate a sample code. thanks.

i'm glad you managed to find my answer. most of the sample code is posted already on this page. is there something specific you don't understand. i'm afraid i have very little time right now, but please add a comment back if you have further issues.
Simon_Weaver
+2  A: 

I had a similar problem, and ended up putting the SWF files in a sub-directory named as the build number. This meant that the URL to the SWF files pointed to a different location each time.

Ideally this should be catered for by the platform, but no joy there. But this works perfectly for us, and integrates very easily into our automated builds with Hudson - no complaints so far.

Stuart
A: 

Looks like i get the accepted answer myself :-(

Simon_Weaver
A: 

Hi Simon or anyone,

How does this apply to RSL? When we load the swf and module using ?verion=xxx approach, does it guarantee to load the non-cache RSL as well?

Appreciate the help.

handitan
A: 

hi Simon or anyone this solution is great. but I am getting another problem. I am using IE6 & FF 3.6 and browsers are trying to download swf file second time when user tries to login. any elegant solution than this java script?

thanks

A: 

hi Harsh here is sample.


function AC_FL_RunContent(){ var ret = AC_GetArgs ( arguments, ".swf?ts=" + getTS(), "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" , "application/x-shockwave-flash" ); AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs); }

function getTS() { var ts = new Date().getTime(); return ts;

}

AC_OETags.js is file and it exists html-template several places. but as my posting said, I am facing another type of problem.

+1  A: 

Flex says:

http://www.adobe.com/livedocs/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001388.html

Akif Tariq
this is specifically intended for performance testing where you NEVER want anything cached. the question is specifically related to over optimistically caching when you don't want it cached. but definitely useful when testing - thanks!
Simon_Weaver
A: 

Stuart, your solution sounds compelling. Will you please provide more details about how you've set up Hudson to do the build so that it automatically creates the SWF in the right directory and the HTML file knows where to get the SWF?

Von
@von i see you're new here and can't comment. stuart probably wont ever see your message though if you just post it as another answer. best to go out there and explore the site - answer some questions and earn a few more points. you'll learn a lot here - and then you can comment on peoples answers and they'll see your reply. or just ask a new question referencing this one and asking for more details. someone else might have something more to offer
Simon_Weaver