The best way to reduce the size of your Flex application (or the resultant SWF file) is to use Runtime Shared Library which uses the concept of dynamic linking.
Normally a Flex application consists of your application code as well as the framework code and the both of these codes are statically merged together in a single SWF file. It makes the resultant size of your application (the SWF file) larger by adding some 500 KB’s of data to it, which has to be downloaded each time the application is downloaded to a client.
On the other hand, RSL allows you to decouple your application code with the framework code and allows you to dynamically link both of them as and when needed (while running the application). Without wasting time, lets try and configure our project to use RSL instead of static linking. It can be done either using command line Compiler Options or by changing certain settings in Flex Builder. We’ll go the easy way:
Setup in Flex Builder
Following Steps are needed to Compile and Build a Project in Flex Builder with RSL in it:
- Select your Flex Project. Click on Project –> Properties
- Go to Flex Build Path
- Open Library Path Tab. By default the framework linkage is statically linked --> Merged into Code as shown below:
Change the drop down to Runtime Shared Library (RSL) for dynamic binding.
Make sure that Verify RSL digests checkbox is checked. Click Ok to complete the changes and the project will be recompiled with updated compiler settings.
This will create 2 files for RSL in the Output Folder of your project:
- framework_3.X.X.XXX.swf (Unsigned/Failover RSL)
- framework_3.X.X.XXX.swz (Signed RSL)
By default, the Flash player will try and use the Signed RSL to link with your application code on loading but the signed RSL works only with Flash Player 9.0.115 and later. If your clients are using a lower version, then it will be unable to load the Signed RSL (swz) and will automatically switch over to the failover RSL (swf) and use it in place of Signed RSL.
A Major benefit of using Framework RSL is caching. RSLs are cached when they are first used. When they are needed by another application, they can be loaded from the cache rather than across the network. The signed framework RSL (RSL’s can be signed by Adobe only) can be cached in the Flash Player cache as well. This benefits by reducing the initial download time as there is no need to download the framework code every time you need to run your Flex Application. And since the caching is done in the special cache of the Flash Player and not in the browser cache, so this signed RSL can be used for some other Flex Application (served from a different domain than yours) On the other hand, the failover RSL is cached in the browser’s cache.
Compiler Settings
Apart from RSL, while building the project for Production Environment, the debug option must be set to false, else the resultant SWF file will also contain the debug information, which is unnecessary for the production environment. To do so, right click the project, go to Project Properties and open the Flex Compiler View and add
-debug=false
in Additional Compiler Arguments as shown below:
Without doing this also, it will work but the resultant SWF file will have debug information with it. The default value of this parameter is true.
Go Check the output folder of your web application and you will definitely see a reduced SWF file there Happy Flexing :-)
No comments:
Post a Comment