views:

846

answers:

3

Would like to know if when an external remote resource (say SWF, or JPG) is loaded using the SWFLoader (or even Image component) in flex3, if there is any client side (ie. browser caching?) or the loaded resources. In particular would a second request then to access a previously accessed resource just use the cached resource or would a new request be made. It would be nice to know if both are possible (ie. telling it to always use a fresh load or to use a cached copy if it is available)

A: 

If it's caching you might avoid it loading the resource with a random var. For example, loading the uri "/background.swf?var=1432".

ktulur
A: 

You should empty your browser cache. This way, once everything works fine caching will still work. What means if I visit 5 times the same website I'll load it only once (that's really convinient).

The solution ktulur suggests works but remember commenting/removing it when you finish.

You could do something like:

var anticache:String="";
anticache = String(Math.random());
var file_url:String = "Whatever.xxx"+anticache;

An then comment/uncomment the second line to use/ignore the anticache method. I hope it helps :)

ozke
+3  A: 

The browser is responsible for caching all externally loaded media, such as images sounds, videos and even SWFs. These can be deleted by clearing your browser cache. I recommend the Clear Cache Button Firefox Add-on for anyone testing there Flash projects in Firefox.

However, Flash Player handles caching of any externally loaded signed Flash components e.g. any Adobe Flex framework components. You can read more about Flash Players cache here. Clearing your browser cache, will not clear these components.

To stop a file being cached by your browser, you will need to make sure its filename is unique each time it is loaded. You can do this by appending a random string as a URL variable. I usually use the current time, or a random number:

var noCache:int = new Date().getTime();
myImage.load("filename.jpg?uniq=" + noCache);

Or you can add the unique variable using the URLVariables class.

TandemAdam