CHAPTER 4
64
// Set expiration date to a date in the past.
response.setDateHeader("Expires", 946080000000L); //Approx Jan 1, 2000
// Force always modified.
response.header("Last-Modified", new Date());
Reducing SWF file sizes
You can improve initial user experience by reducing the time it takes to start an application. Part of this time is
determined by the download process, where the SWF file is returned from the server to the client. The smaller the
SWF file, the shorter the download wait. In addition, reducing the size of the SWF file also results in a shorter
application initialization time. Larger SWF files take longer to unpack in Flash Player.
The mxmlc compiler includes several options that can help reduce SWF file size.
Using the bytecode optimizer
The bytecode optimizer can reduce the size of the Flex applications SWF file by using bytecode merging and
peephole optimization. Peephole optimization removes redundant instructions from the bytecode.
If you are using Flex Builder or the mxmlc command-line compiler, you can set the optimize compiler option to
true, as the following example shows:
mxmlc -optimize=true MyApp.mxml
The default value of the optimize option is true.
Disabling debugging
Disabling debugging can make your SWF files smaller. When debugging is enabled, the Flex compilers include
line numbers and other navigational information in the SWF file that are only used in a debugging environment.
Disabling debugging reduces functionality of the fdb command-line debugger and the debugger built into Flex
Builder.
To disable debugging, set the
debug compiler option to false. The default value for the mxmlc compiler is false.
The default value for the compc compiler is
true.
For more information about debugging, see “Using the Command-Line Debugger” on page 245.
Using strict mode
When you set the strict compiler option to true, the compiler verifies that definitions and package names in
import statements are used in the application. If the imported classes are not used, the compiler reports an error.
The following example shows some examples of when strict mode throws a compiler error:
package {
import flash.utils.Timer; // Error. This class is not used.
65ADOBE FLEX 3
Building and Deploying Adobe Flex 3 Applications
import flash.printing.* // Error. This class is not used.
import mx.controls.Button; // Error. This class is not used.
import mx.core.Application; // No error. This class is used.
public class Foo extends Application {
}
}
The strict option also performs compile-time type checking, which provides a small optimization increase in
the application at run time.
The default value of the
strict compiler option is true.
Examining linker dependencies
To find ways to reduce SWF file sizes, you can look at the list of ActionScript classes that are linked into your SWF
file.
You can generate a report of linker dependencies by setting the link-report compiler option to true. The output
of this compiler option is a report that shows linker dependencies in an XML format.
The following example shows the dependencies for the ProgrammaticSkin script as it appears in the linker report:
<script name="C:\flex3sdk\frameworks\libs\framework.swc(mx/skins/ProgrammaticSkin)"
mod="1141055632000" size="5807">
<def id="mx.skins:ProgrammaticSkin"/>
<pre id="mx.core:IFlexDisplayObject"/>
<pre id="mx.styles:IStyleable"/>
<pre id="mx.managers:ILayoutClient"/>
<pre id="flash.display:Shape"/>
<dep id="String"/>
<dep id="flash.geom:Matrix"/>
<dep id="mx.core:mx_internal"/>
<dep id="uint"/>
<dep id="mx.core:UIComponent"/>
<dep id="int"/>
<dep id="Math"/>
<dep id="Object"/>
<dep id="Array"/>
<dep id="mx.core:IStyleClient"/>
<dep id="Boolean"/>
<dep id="Number"/>
<dep id="flash.display:Graphics"/>
</script>

Get ADOBE® FLEX® 3: BUILDING AND DEPLOYING ADOBE FLEX 3 APPLICATIONS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.