How to optimize the SWF file in a Flex application?


I found this answer in the Flex India User Group mailing list today. The answer has been given by Saurabh Narula in response to a question by Khalid Chaudhary.

The question is this –

When we create a new Flex project using the FB IDE and immediately do a File->Export->Release Build, then the size of the resultant SWF file is roughly 160 – 170 KB.  But if you use RSLs – rpc.swf, framework_3.2.0.3958.swz, framework_3.2.0.3958.swf and flex.swf – to compile your application, then the Size of the application’s SWF file is just around 60-70KB. How and why does the size of the SWF file go down?

The answer (given by Saurabh Narula) is –

Flex framework is nothing but a bunch of classes implemented over Flash Player APIs.  When you create a flex project you are building a project using all the classes required to build your “Flex” project, so by default the flex framework which is close to 150kb would be included/compiled if you create a flex project. If you create an actionscript only project then you would see that flex framework would not be included by default and your swf size would be considerably low. Now, if the client request for a swf file (built using a flex framework), the flash player client will load the full swf file along with the framework classes, this will happen repeatedly.

If you compile using a framework RSL then your swf size would be cosiderably small, because your framework(RSL) would only be loaded once in the flash player(cached), repeated requests to the swf file would not load the flex framework classes as they already available to the flash player in its cache.

The goal of this post is to make this answer accessible to non-subscribers of the mailing list. Credit for the answer solely goes to Saurabh Narula.

Does that mean that everyone should compile their flex apps using RSL as a standard practice? I dont know, I will try it and post my observations on this blog. In the meanwhile, if you happen to be a Flex Guru reading this post, do share your thoughts on the whether its a good idea to compile flex applications using framework RSLs as a standard practice.

Advertisements

About vatsalad

Hi, I'm Vatsala
This entry was posted in Adobe Flex, flex, How To... and tagged , . Bookmark the permalink.

4 Responses to How to optimize the SWF file in a Flex application?

  1. Hi,

    You were spot on with your observations about turning out RSLs by default, it would be a good practice in most of the cases to turn it on by default, please note that the RSLs are turned on by default in flex 4, to know more about the enhancements to RSLs in Flex 4, you can check out http://opensource.adobe.com/wiki/display/flexsdk/RSL+Enhancements

    Saurabh

  2. octav says:

    is true most of it, the initial swf will be smaller, and the libs will be requested after the main swf is loaded, and cached, but is not a big difference since embedding everything in your main swf will get you the same result pretty much because swfs are cached by browsers with default configurations

    Also the size with everything embedded i think is smaller than taken independent, also, the number of requests to your server is smaller, consider few thousands users and rpc and framework required, most of the time you require even more, like skins , 3rd party stuff etc, for each of them a request will be made so having 2 shared libs will require thrice as many requests something that could kill your web server faster.

Comments are closed.