Using framework RSLs

Tired of large Flex SWF files size? Runtime Shared Libraries (RSL) can solve that problem. Runtime Shared Libraries change the default behavior of library compilation from static (merging dependencies into your code) to dynamic (dependencies are loaded at runtime). If you use the same library (same the Flex framework SWC) across many SWFs, you can dramatically reduce file size by only downloading the library once at runtime.

To compile a library as an RSL, you must change dependency scope to rsl. Like this:

<dependencies>
  <dependency>
    <groupId>com.adobe.flex.framework</groupId>
    <artifactId>framework</artifactId>
    <version>4.6.b.23201</version>
    <type>swc</type>
    <scope>rsl</scope>
  </dependency>
</dependencies>

It's possible to use a signed RSL (SWZ), known as Caching Framework. For this the scope is caching:

<dependencies>
  <dependency>
    <groupId>com.adobe.flex.framework</groupId>
    <artifactId>framework</artifactId>
    <version>4.6.b.23201</version>
    <type>swc</type>
    <scope>caching</scope>
  </dependency>
</dependencies>

(For more details about using caching framework have a look here)

The dependency defines which libraries should be loaded as RSL. But it's still necessary to define where the libraries will be loaded from at runtime.
In order to define the RSL location is necessary to add a template URL on pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>net.flexmojos.oss</groupId>
      <artifactId>flexmojos-maven-plugin</artifactId>
      <configuration>
        <rslUrls>
          <rsl>{artifactId}-{version}.{extension}</rsl>
        </rslUrls>
      </configuration>
    </plugin>
  </plugins>
</build>

The first RSL URL in the list is the primary RSL. The remaining RSL URLs will only be loaded if the primary RSL fails to load.

The rslUrl accept some special tokens:
{contextRoot} - replace by defined context root
{groupId} - replace by library groupId
{artifactId} - replace by library artifactId
{version} - replace by library version
{extension} - replace by library extension swf or swz