Adobe Flex; how to cache main application - apache-flex

Does Adobe Flex support caching of the main application; i.e. if the user had previously loaded it and it hasn't been modified since last loaded, can the browser get the swf file etc. from it's cache? I'm on an embedded system with boa as the web server, so can modify any behavior there as needed.
Thanks,
Fred

Not sure if the actually is an answer to your question, but I can tell you that the browsers will cache the swf files as long as it is referenced the same way within your html.
Ie. we use src="myApp.swf?dummy=102032" when referencing to it to avoid caching. You can use httpfox or any other networking monitor tool to see when your swf is cached.

The browser does the caching automatically just like any other file you view through it. As long as the user has a cache setup in the browser, there shouldn't be a problem unless the URL to the file changes (that includes query strings).
There is also RSL caching, if you are using RSLs. By default, they are just in your output folder as SWFs, but you can use the Adobe signed RSLs which are of the SWZ extension, are hosted on the Adobe site, and are cached at the Flash Player level, not the browser. This means that even if a user has caching disabled in the browser, it will cache the RSL either way.

Related

Do css background images not get cached by default?

While tuning my web app, I noticed that certain of my images are never loading from cache, even though they're completely static:
This particular file always loads from the server, but it should be cached. The only thing somewhat special about the file, AFAICT, is that it's sourced via a CSS class, which specifies the file via a background-image style. I'm not specifying any tricky headers or anything; it's just a regular jpg file.
There's a lot online about preventing caching, but I can't find anything about making it work when it doesn't seem to be.
Do you have caching software on your web server? If yes is it enabled? Since some can be disabled such as UnixyVarnish what is mainly found in cPanel. Images do get cached by default. Regardless of how its displayed. And your browser should automatically cache websites you visit, unless you have disabled it.

Should I embed CSS/JavaScript files in a web application?

I've recently started embedding JavaScript and CSS files into our common library DLLs to make deployment and versioning a lot simpler. I was just wondering if there is any reason one might want to do the same thing with a web application, or if it's always best to just leave them as regular files in the web application, and only use embedded resources for shared components?
Would there be any advantage to embedding them?
I had to make this same decision once. The reason I chose to embed my JavaScript/CSS resources into my DLL was to prevent tampering of these files (by curious end users who've purchased my web application) once the application's deployed.
I doubting and questioning the validity of Easement's comment about how browsers download JavaScript files. I'm pretty sure that the embedded JavaScript/CSS files are recreated temporarily by ASP.NET before the page is sent to the browser in order for the browser to be able to download and use them. I'm curious about this and I'm going to run my own tests. I'll let you know how it goes....
-Frinny
Of course if anyone who knew what they were doing could use the assembly Reflector and extract the JS or CSS. But that would be a heck of a lot more work than just using something like FireBug to get at this information. A regular end user is unlikely to have the desire to go to all of this trouble just to mess with the resources. Anyone who's interested in this type of thing is likely to be a malicious user, not the end user. You have probably got a lot of other problems with regards to security if a user is able to use a tool like the assembly reflector on your DLL because by that point your server's already been compromised. Security was not the factor in my decision for embedding the resources.
The point was to keep users from doing something silly with these resources, like delete them thinking they aren't needed or otherwise tamper with them.
It's also a lot easier to package the application for deployment purposes because there are less files involved.
It's true that the DLL (class library) used by the pages is bigger, but this does not make the pages any bigger. ASP.NET generates the content that needs to be sent down to the client (the browser). There is no more content being sent to the client than what is needed for the page to work. I do not see how the class library helping to serve these pages will have any effect on the size of data being sent between the client and server.
However, Rjlopes has a point, it might be true that the browser is not able to cache embedded JavaScript/CSS resources. I'll have to check it out but I suspect that Rjlopes is correct: the JavaScript/CSS files will have to be downloaded each time a full-page postback is made to the server. If this proves to be true, this performance hit should be a factor in your decision.
I still haven't been able to test the performance differences between using embedded resources, resex, and single files because I've been busy with my on endeavors. Hopefully I'll get to it later today because I am very curious about this and the browser caching point Rjlopes has raised.
Reason for embedding: Browsers don't download JavaScript files in parallel. You have a locking condition until the file is downloaded.
Reason against embedding: You may not need all of the JavaScript code. So you could be increasing the bandwidth/processing unnecessarily.
Regarding the browser cache, as far as I've noticed, response on WebRecource.axd says "304 not modified". So, I guess, they've been taken from cache.
I had to make this same decision once. The reason I chose to embed my JavaScript/CSS resources into my DLL was to prevent tampering of these files (by curious end users who've purchased my web application) once the application's deployed.
Reason against embedding: You may not need all of the JavaScript code. So you could be increasing the bandwidth/processing unnecessarily.
You know that if somebody wants to tamper your JS or CSS they just have to open the assembly with Reflector, go to the Resources and edit what they want (probably takes a lot more work if the assemblies are signed).
If you embed the js and css on the page you make the page bigger (more KB to download on each request) and the browser can't cache the JS and CSS for next requests. The good news is that you have fewer requests (at least 2 if you are like me and combine multiple js and css and one), plus javascripts have the problem of beeing downloaded serially.

When an swf (or other external remote resource) is loaded using SWFLoader, is there any client side caching performed

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)
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.
If it's caching you might avoid it loading the resource with a random var. For example, loading the uri "/background.swf?var=1432".
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 :)

Caching of swf files in Flex application

I've created a Flex application and the size of the swf file is ~900KB.
My trouble is that the files are not getting cached. When I launch the application for the second time, the swf file is fetched again from the server.
I'm including the swf file in a jsp, and I'm not modifying any HTTP Caching Headers. I assumed that the swf files will be cached automatically. Isn't it so?
How do I forcefully cache the file? Do I need to provide anything in the MXML code or just a response.setHeader("Cache-Control","max-age=100"); is enough? Can anything be done from the flex side itself?
Suggestions please...
I presume you mean that your JSP page generates HTML which contains a reference to the SWF - this would be the common case. In this case, there are (at least) two HTTP requests made by the browser - one for the JSP page and one for the SWF file. As the SWF file is static, it may be served up by your J2EE server or by your webserver (e.g. Apache), depending on your configuration. You will need to check what cache settings are applicable to your static content (e.g. images) and ensure that those settings prevent caching of the SWF. Your JSP cache settings will only affect the HTML and not the SWF.
Ideally, browse your site using Firefox and Firebug and check the headers for each HTTP request (Firebug's Net tab). This should give you the information you need about what headers are applicable to the SWF.
I would assume that the request for the SWF is separate from the request for your JSP page (just like requests for images are separate). Thus, you probably need to configure your server to serve SWF files with a specific cache header. I doubt changing the cache settings for the JSP page will make a difference.

Does Flex save stuff to the local cache on client computer?

My Flex app downloads a bunch of images. When the user closes the browser window (or navigates away from the page), those images shouldn't be saved in the local cache. HTTP headers for the SWF file tells browser to fetch it from the website every time -- that is, it shouldn't save the SWF file locally. I just want to make sure that any of the images that the Flex app downloads isn't saved locally.
I checked Windows XP & Flash 9 for this. And nothing was stored locally. I assume this is true across all platforms and all versions of Flash greater than 9?
Thanks!
I think that flash download contents using the underling browser so the browser caches contents for him. In my experience sometimes browsers fails to read HTTP infos for caches and uses data from cache even if the file on the server is newer. The only way that works for sure to disable caching is changing the name of the file everytime you download it.
For example you can add a random string or a timestamp to your request. image1.gif is image1.gif?nocache=1231231

Resources