Faster Flex Applications: Shrink Your RSLs

A few days ago Metal pointed out to me in a comment on my blog that by using the SWFs inside a SWC, my RSLs are much larger than they need to be. Sure enough he was right. When you use compc to create a SWC, the SWF inside the SWC contains a lot of unnecessary stuff when used as an RSL. That stuff is necessary to create an application which uses the SWC, so don’t go ditching compc. Here is what you need to do if you want to have size optimized RSLs:

1) Create an ActionScript class that extends Sprite and includes references to the stuff you want to go into your RSL. For instance:

package
{
import flash.display.Sprite;
import mx.core.Application;

public class smallLinker extends Sprite
{
private var application:Application;
}
}

2) Compile your SWC:

compc -debug=false -o=my.swc smallLinker

3) Compile your RSL:

mxmlc -o=my.swf -file-specs=smallLinker.as

4) Compile your application:

mxmlc -external-library-path+=my.swc \
-runtime-shared-libraries=http://www.yourhost.com/my.swf \
-o=app.swf -file-specs=app.mxml

5) Upload app.swf and my.swf to your host.

6) Run your application and verify it works.

7) Send me a check for the money you save on bandwidth (Don’t worry Metal, we will split it 60/40).

If you compare the size of the SWF inside the SWC and the SWF created with mxmlc, you should see a very large difference. Since your new SWF is much smaller than your old one, your application will take less time to load across the wire. Fun stuff!

This entry was posted in Flex. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. calderas
    Posted February 20, 2007 at 10:30 pm | Permalink

    Great Article James/Metal
    I’ve been working with RSL’s lately, and both of your articles have been very helpful.
    Thanks to this I could take down more than 50% of the previous SWF.
    There aren’t many examples out there about this, not even in the Flex Documentation.
    I think you guys (Flex Team) are doing hell of a job bloging and interacting with the community as new ideas, problems and solutions arise.

    Thanks,

2 Trackbacks

  1. [...] James Ward?s Blog ? Blog Archive ? Faster Flex Applications: Shrink Your RSLs – Here is what you need to do if you want to have size optimized RSLs [...]

  2. [...] James Ward shares his insights into compiling RSLs in order to to shrink them [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Subscribe without commenting