Skip to content
November 15, 2008 / Shrikant Patil

Using Runtime Shared Libraries – Utilizing Flash Player Cache

This post is intended to highlight on new Flash Player [Flash Player 9 Update 3 (9,0,115,0)]cache feature using Flex and focus on overview of RSL’s in Flex 3 framework.

As we know that when we compile a Flex Application, the resulting SWF file includes the compiled application code along with framework code as well. Which results increase in size application SWF file. When user opens the application, the application starts downloading, more the size application SWF has, will result the delay in application startup. So it is important to understand the features flex provides to overcome with this problem.
The way flex provides to reduce the application’s SWF file by externalizing the shared files. These files can be separately downloaded and stored on either browser or Flash Player cache. Afterwards, any number of applications can utilize these cached files at runtime. Assume that we have some set of classes and components which can be used by multiple applications, then we can make those classes and components as RSL files and externalize them, so that client can download them separately. Once these file stored in client cache, so that multiple application can utilize same RSL file.
These externalized files get transferred to client only once i.e at first attempt of application startup. So the files become shared resources, so that any number of applications can utilize these cached externalized files. These externalized and shared files are known as Runtime Shared Libraries (RSL’s).

Flex application has type of RSL’s:

Standard RSL’s:
A library of classes, which are intended to use in multiple applications which are in same domain. Consider we have multiple applications on same domain http://www.aa.com , and both application are going to use some common set of classes. Then we can make those set of common classes as Standard RSL files. The thing need to consider is that, suppose say another application from domain http://www.bb.com cannot use this Standard RSL.  Standard RSL are used by the applications from same domain. Standard RSL’s get stored on clients browser cache. If client clears the browser cache the Standard RSL also get cleared.

Cross Domain RSL’s:
A library of classes, which are intended to use in multiple applications irrespective of domain. Cross Domain RSLs can be used by the applications form any domain or sub domains. Consider a Cross Domain RSL is downloaded stored at cache of client from the domain http://www.aa.com. The applications form domains like http://www.bb.com and http://www.cc.com can use this RSL.
To use Cross Domain RSL, the remote server which hosts the Cross Domain RSL should contain crossdomain.xml file, which allows access from the RSL domain. It is better to put the crossdomain.xml file at root of the server. If you intend to put it somewhere else, then you need to specify in the path of crossdmain.xml on server, while compiling the Cross Domain RSL.
Cross Domain RSL’s get stored on clients browser cache. If client clears the browser cache the Cross Domain RSL’s also get cleared.

Let us consider these two RLS types to get big picture; (we consider third type: Framework RSLs bit later)
To understand, work and to create the Standard and cross domain RSL’s we need to understand some terms;
1) Linking 2) RSL Caching 3) RSL Digests 4) RSL Compiling

Lets us go through one by one;
1) Linking: The Flex is framework written in ActionScript. It contains framework file in the form of SWC files which are linked to our application so that we can use the framework. Likewise if we create a externalized custom library with set of classes and want to use in flex applications we need to link our application to that library. The linking can be done in two ways;
a)  Static Linking (Merge into Code) and
b) Dynamic Linking (Runtime Shared Library).

When we link a custom library using static linking, the compiler includes all library reference and dependent classes in the application SWF file. This makes a heavy sized SWF file which take longer time to download.
To set Static linking on any of custom library (SWC),
a) Select project => properties => Flex Build Path, choose ‘Library Path‘ Tab.
b) Add new SWC or select exiting SWC, and click on dropdown of ‘Framework Linkage’, and choose ‘Merged into code’.

The power of RLS is hidden in dynamic linking. When we link a custom library using dynamic linking, the compiler compiles linked library as separate file (either SWF or SWZ) along with application SWF. Means compiler externalizes the custom library, which can separately download and cached on client. This reduces the size and startup time of application SWF.
To set Dynamic linking on any of custom library (SWC),
a) Select project => properties => Flex Build Path, choose Library Path Tab.
b) Add new SWC or select exiting SWC, and click on drop down of ‘Framework Linkage’, and choose ‘Runtime Shared Library’.

2) RSL Caching:
When a client opens Flex application first time which uses RSL, the RSL gets downloaded and cached. Means when Flex application which uses any RSL is opened on client browser, it checks weather the RSL is already cached or not, if application is running first time then it will not get the cached RSL, so it start downloading it from the domain. If application running afterwards of first attempt, then it gets the cached RSL (which was get cached when application ran first time), so application uses the cached RSL instead downloading it again. Considering this point of view, we can understand that, the flex application which uses RSL’s are also slowdown when it is running for first time. But they run comparatively fast from second attempt, because RSL is available on client disk instead from network.
Caching done in twp ways, Standard and cross domain RLS are get cached on browsers cache. If user clears the browser cache, the cached RSL’s are also gets removed and must be downloaded again when next time they needed by any of flex application on client.

The third type of RSL ‘Framework RSL’, are cached on Flash Player Cache.( we look more about Framework RSL later)

3) RSL Digests:
In case of cross domain RSL’s, flash player needs to ensure the requesting RSL coming from trusted domain (the domain which has crossdomain.xml file). Flash player checks bytes of coming RSL and computes against digest. The digest information coming must match the with the digest what was stored in application, which was created while application linking with RSL and compiling it. If comparison doesn’t match then flash player throws error, if comparison of digests matches flash player loads the cross domain RSL.
To create a digest while compiling a cross domain library, use -compute-digest=true option on compiler arguments. And to set the application should check RSL digest, use –verify-digests=true compiler argument.

Creating applications with Standard and cross domain RSL’s:
Compiling the application with standard and cross domain RSL’s can be done either by using Flex Builder or command line compiler. I am going to explain only Flex Builder steps. Ensure that you have a MyLib.swc (any sample library, compiler to SWC file) to proceed with below steps;

a)    Select project => Properties, select Flex Build Path and click on Library Path Tab.
b)    Click on ‘Add Swc’ enter the path for MyLib.Swc file and click on OK.
c)    Now the MyLib.swc file is added to Flex Library Path list tree, expand the MyLib.swc tree node, it opens child nodes of MyLib.swc file.
d)    Select ‘Link Type’ and click on ‘Edit’. Change the ‘Link Type’ to ‘Runtime Shared Library’. Select the radio button of ‘Digests (Recommended). Click on ‘Add’ button. It takes default name of SWF file as ‘MyLib.swf’ at Deployment Path/URL field.
e)    For the field of ‘Policy file URL’ specifies the path of crossdomain.xml’ file (this step is for only cross domain RSL).
f)    If you are going to use cross domain RSL, make sure that you must select ‘Varify RSL Digest’ option in Library Path Tab.
g)    Click on OK.
This is what all about Standard and cross domain RSL’s;

Let us move to third type of RSL, i.e Framework RSL

Framework RSL:
Framework RSL’s are pre compiled libraries of Flex components and framework classes, which can be shared by all flex application. These libraries are precompiled, means there is no need to compile these libraries to SWC, and flex provides precompiled SWC files to use this feature.
Every flex application uses the flex framework. Flex framework is actually a large set of ActionScript classes which define the infrastructure of a Flex Application. Assume that we have two Flex applications, either in same domain or different domain. Each time when either of any application starts to run, the standard flex framework is also downloaded for each of the application; this is because the flex framework is compiler within application SWF for each application. Assume that there are two flex applications running on client; both applications have a set of copy of flex framework files. This is unnecessary to have separate framework copy for each application. This is where the Framework RSL comes. In this model, Framework RSL’s are cached on Flash Player’s cache (Note that Framework RSL’s are cached at Flash Player Cache, not at browsers cache), and same framework can be utilized by all flex applications. The cached framework is not removed even if you close the flash player that can be removed by flash player manager.
Framework RSL’s are two types; 1) Signed and 2) unsigned
Signed framework files are stored in flash player’s cache instead of browser cache. They can be utilized by any applications irrespective of any domain. These framework files need to be downloaded only once to the client.
Unsigned Framework files are stored in browser cache, and can be used by applications that have access to the RSL’s domain.

The flash player with version 9.0.115 or later only support for loading Signed Framework RSL’s. The signed Framework files have extension SWZ. Because security reasons only Adobe can create signed framework RSL’s, we cannot create signed framework RSL’s.
So what if a client has a Flash player lower version than of 9.0.115? The answer comes with failover RSL. Failover is also framework RSL in the form of SWF (not in SWZ) format. The flash player with the version 9.0.115 or above can load framework SWZ file, else the flash player version lower than of 9.0.115 cannot load framework SWZ file. So while creating the framework RSL we need to specify that alternate SWF file to load when client has flash player version lower than of 9.0.115. when SWZ file failed to load because of flash player version the failover file (SWF) is loaded. Following are the list of Adobe signed framework files;
•    framework_3.0.bild_number.swz(signed framework RSL)
•    framework_3.0.build_numver.swf(unsigned framework RSL)
•    rpc_3.0.build_number.swz(signed framework RSL)
•    rpc_3.0.build_number.swf(unsigned framework RSL)
•    datavisualization_3.0.build_number.swz(signed framework RSL)
•    datavisulazation_3.0.build_number.swf(unsigned framework RSL)

So let’s go with creating framework RSL to reduce the application file size.
First we look into how to make signed framework RSL. Flex uses framework.swc file, which includes almost flex framework classes. If we externalize this from application by creating signed framework RSL we can reduce the application file size.
1)    Create an application in flex, insert a label component and put some text for text property of label component. Save the document. Check the compiler application SWF file size, it may around 241K.
2)    Select project=>properties, select ‘Flex Build Path’, click on ‘Library Path’ Tab.
3)    Expand the Flex 3 node, locate the framework.swc & expand it, click on ‘Framework Linkage’ drop down and select ‘Runtime Shared Library’.
4)    Click on OK. Now go and check the folder ‘bin-debug’. The application SWF file’s size is around 71K. And u can see two extra files also appear, framework_3.0.—.swz and framework_3.0.–.swf. Which are signed framework RSL and unsigned framework RSL files.
If you deploy this application on server you can check the startup speed of application.

In the same way you can change other signed and unsigned framework RSL provided by Adobe.

You find how to create framework RSL’s ar below link;
http://www.adobe.com/devnet/flex/articles/flash_player_cache_print.html

Leave a comment