Select to view content in your preferred language

Preventing client-side caching of the Flex Viewer

4723
9
11-05-2010 04:32 AM
MattiasEkström
Frequent Contributor
Hi!

When I've made some updates to my custom Flex Viewer 2.1 application and publish the new version on our server, my colleagues don't see those changes because the old version is stored in their browsers cache. Deleting all ache files will fix this, but I don't want them to have to do that all the time.
I've searched for some info on how to prevent client-side caching, and it seems like the most common solutions is to either and some random number or time-stamp to the url when calling the swf-fil (something like index.swf?time='time-stamp', or to "set the HTTP headers for the SWF file request in the HTML wrapper"
Here's some example code to do this in JSP:
// Set Cache-Control to no-cache. 
response.setHeader("Cache-Control", "no-cache"); 
// Prevent proxy caching. 
response.setHeader("Pragma", "no-cache");  
// Set expiration date to a date in the past. 
response.setDateHeader("Expires", 946080000000L); //Approx Jan 1, 2000 
// Force always modified. 
response.header("Last-Modified", new Date());

(From the Adobe help documentation)

I've also seen similar examples in PHP.

My problem is I don't know how to use this code with my Flex Viewer application, I hardly know what JSP is.
I guess I should do something with the index.html or the index.template.html (to keep the changes when rebuilding my project)

Or maybe someone has another solution to my problem?
Tags (2)
0 Kudos
9 Replies
DasaPaddock
Esri Regular Contributor
You can change the first argument to the swfobject.embedSWF() function in the index.template.html to something like this:

"${swf}.swf?ts=" + new Date().getTime()
0 Kudos
MattiasEkström
Frequent Contributor
Dasa, I changed the swfobject.embedSWF() function as you suggested, but without the result I was looking for. You still have to clear the cache memory to see the changes made to the application.
I wonder if this change only affect the index.swf? Then maybe index.swf is not loaded from the cache memory, but all other swfs are, all widgets and controls. And that's were all the changes are made. If this is the case, how could I use this method on all the swf-files?

Or do I have to use some other method?
0 Kudos
TomSchuller
Frequent Contributor
Dasa, your tip is working for the main "index.swf" file.

How could I make this working for the several widgets-swf-files?
We are also sawing that the config files are cached (main+widget's configs)

Thanks,
Tom
0 Kudos
DasaPaddock
Esri Regular Contributor
You could update the ConfigManager or WidgetManager code to add a ts timestamp to the widget urls.
0 Kudos
MelissaPrindiville
Emerging Contributor
You could update the ConfigManager or WidgetManager code to add a ts timestamp to the widget urls.


Could you provide an example for this?
0 Kudos
xiaoyizhang
Deactivated User
Did you ever resolve the SWF cache issue? What the method you use?
Thanks
0 Kudos
xiaoyizhang
Deactivated User
You could update the ConfigManager or WidgetManager code to add a ts timestamp to the widget urls.


dpaddock,

Can you tell me how to update the ConfigManager or WidgetManager code to add a ts timestamp to the widget urls?

Thanks

xzhang
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
xzhang,

   Actually all the work is done in the ConfigManager.as.

Here is the code for FlexViewer 2.3.1 with timestamps added to all widgets and their xml files.
0 Kudos
DarrenGemoets
Occasional Contributor
So...sorry for a blatantly necro-ing this very old post, but it's exactly what I'm trying to do, and the changes to ConfigManager.as do not appear to be working for me.  I'm using a slightly older version of the FlexViewer than the example for this post, but applying the timestamp changes appeared to be a straight-forward merge into my version of ConfigManager.as.

Are others able to prevent client-side caching of their apps?  It seems like a desirable thing to do unless you can get away with asking your users to clear their cache every time you update your app.

I'm also certainly open to other (non-ConfigManager) anti-caching approaches.
0 Kudos