Our Blog

If you want to use a library in your Flex project, distributed as a SWC file, you should not look at the SWC file size as any indication of how much your compiled application will increase in size. If you want to know how much size overhead the library imposes, look at the compiled release version of your app (Click on Export Release Build button). Even then, it will depend on how much of the library you are using.

I've heard at least twice people complaining that Mate's SWC was over 600KB, thinking that using Mate in their projects would be prohibitive because it would make their app's file size to be over 600KB. It's easy to see that is not true by looking at any of the examples in the website. While they are all small apps, none of them is over 350KB, the largest ones being those that have the most embedded assets such as images. (Since then, Mate went on a strict compiler diet, see last paragraph).

This is either a misunderstanding of how things work or a confusion between SWC and RSLs (Runtime Shared Libraries), which are actually loaded at runtime and therefore will effectively increase the total amount of data the app needs to run. When "Merging the library into the code" (a setting in the Flex Build Path screen in Flex Builder), the compiler will be smart enough to leave classes that are not used in the app out of the final SWF. This is the default setting whenever you add a SWC to your library path. In our tests, using Mate increases your SWF file size by around 10 to 20KB (again this depends on what you use of Mate).

You could, also, export the SWC file separately, making it an RSL. In this case, the whole library is exported, even if you there are parts you don't use. Using this setting is good when you want to share this library among different Flex apps because the library is removed from the final SWF file, and loaded separately so that the browser can cache it. In this case as well, the library SWF that gets exported separately from your app is smaller than the original SWC, so here again, you can't look at the SWC file size, you need to see how big it is when exported. Because the whole library is exported though, most of the time the library SWF file will be larger than the overhead the library would have imposed if merged into the code. For example, adding Mate to your app may increase the final file size by 20KB. Those 20KB can be removed if you externalize the library by creating an RSL. However, the RSL SWF will be 32KB, which is more than the 20KB you removed. But if you have at least 2 apps using Mate that point to the same RSL, then you will start saving bandwidth.

So, if you want to consider using a library for your Flex project, do not judge it by its SWC file size.

By the way, Mate's SWC file is now only 60KB. Thanks to a suggestion from Theo, we were able to remove the Flex framework dependencies that were included in the SWC and that were not really needed. Theo explains a bit more in the forums.




  1. Kevin Hoyt
    In general, I think most developers (skeptics?) would be surprised by just how small you can get a Flex application. Between externalizing the Flex framework and effective use of modules, you can really get far.

    That being said, I also think that the emphasis on the size of a Flex application is really unnecessary for many uses (i.e. applications). Take a hop on over to Amazon today and you'll find the landing page weighing in at somewhere north of 1 Mb. CNN, which is largely a textual site, comes in just shy of 1 Mb. Looking for something more like an application? My Google Mail inbox comes in at well north of 2 Mb. My bare bones Google Docs home page is almost 1 Mb.

    Do we really need to be calling out something in the 300k to 600k, especially considering all the functionality that application will likely have?

    Two cents,
    Kevin Hoyt
    Adobe Systems, Inc.
  2. Theo
    Good write-up Laura! I was going to sum it up on my blog, but now there's no need.

    There's one other thing about not including the Flex framework in distributed SWCs: in a project you may use a number of SWC-packaged libraries, if each one contains a subset of the Flex framework the linker has many versions of the Flex classes to choose from. I'm not sure about how it chooses which class to include, but it's probably more or less only down to which version it finds first. What happens then if one SWC was built using Flex 2, another using Flex 3 and a third Flex 4? You get lots of strange errors, that's what. I experienced some during the time Flex 3 was in beta, libraries built with the previous beta version didn't work so well with applications built with the latest, and vice versa.

    Distributing SWC with only your code is a virtue all framework and library authors should learn. Never mind the smaller file size, but you will save your users from strange compatibility problems. Besides, you have no reason to distribute code that the user will have anyway.


    On another note, I agree with Kevin completely, 300 Kb is nothing to worry about in this day and age -- and it's all about expectations and usage patterns.

    When I visit a site like CNN I will stay 20 seconds, scanning the headlines, that makes 1 Mb a lot, the page may not even have loaded completely when I leave -- but when I visit GMail I will usually leave the window open the rest of the day, so 2 Mb is nothing.