Monday, January 26, 2009

Force Browser to get new version of cached swf file

How to make the request to server only if new version of swf file?

It is very common opportunity, that whenever any new changes are made to the swf file it does not load into the browser as swf is already in browser
cache. At the sametime, you do not want to make the request every time to the server when swf file is accessed. You want to make the request to server only if new version of file is on server. To get rid of the issue, follow the steps.

In the file AC_OETags.js, inside function AC_GetArgs

1.
modify the statement : args[i+1] = AC_AddExtension(args[i+1], ext);
to : args[i+1] = AC_AddExtension(args[i+1], ext+"?v="+appVersion);


2.
add case statement

case "appversion":
appVersion = args[i+1];
break;

3.add global variable in the AC_OETags.js
//Application Version
var appVersion = '1';

Now changes in the .html file where flex swf is embedded
4. Modify the function in the

AC_FL_RunContent(
"appversion", applicationVersion,
"src", "Sow",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "Sow",
"quality", "high",
"bgcolor", "#869ca7",
"name", "Sow",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);


5. Declare the
//Application Version
var applicationVersion =

Conclusion:
Every time a new version of swf comes , change the "applicationVersion". In the below request there will always be new version value which will force browser to make request to the webserver
If you see the request it will be
http:///SOW/Sow.swf?v=2.0.0

No comments:

Post a Comment