Wednesday, April 22, 2009

Flex 3 Modules preventing caching

How to prevent Flex modules from being cached in the browser was an issue when I had state workers who couldn't clear cache on IE.

So I've come up with an apache rewrite option

create a .htaccess file in your webfolder where the swf's are stored

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^nutrition[0-999]+\.swf nutrition.swf [NC]
RewriteRule ^create_meals[0-999]+\.swf create_meals.swf [NC]

I've got two modules that I use in this example nutrition.swf and create_meals.swf

you'll notice i've now setup this so any request coming to nutrition0.swf comes to nutrition.swf file. the range from 0 to 999 allows a random number to be used in flex when calling the modules and thus the browser will think it's a new file.

heres what flex will look like

in your script tag
public var randomnumber:Number = Math.ceil(Math.random()*100);

in your mxml


now you have a no cache option for loading modules

also see my post on not caching flex app at all.

No comments:

Post a Comment

Got a Suggestion please let us know