Cache and preload Gaia pages
Monday, January 25th, 2010
I use Gaia a lot. I think it’s a great and powerful framework to create page-based Flash sites. But there is a problem: Gaia creates a SWF for every page. And every time you visit a page, the SWF is loaded again. Even if you already visited that page. Also it is not possible to preload pages you are not visiting.
To make page caching and page preloading possible, I have created the ‘CacheLoader‘ and ‘CacheURLLoader‘ classes. Both classes make use of the ‘LoaderCache‘ to cache the SWF files used by Gaia. Just add these 3 classes to your project and you only have to adapt 2 Gaia classes to enable this feature:
1) Make the DisplayObjectAsset use the CacheLoader instead of a Loader: Open ‘com.gaiaframework.assets.DisplayObjectAsset’ and change line 58 to:
1 | _loader = new CacheLoader(); |
And set EventListeners on this _loader instead of his contentLoaderInfo (line 60)
1 | addListeners(_loader); |
And update your imports.
2) Make the ByteArrayAsset use the CacheURLLoader instead of an URLLoader: Open ‘com.gaiaframework.assets.ByteArrayAsset’ and change line 42 to:
1 | loader = new CacheURLLoader(); |
And update your imports.
Now all pages are cached in the LoaderCache. The SWF files are only loaded once. (Notice that the progress and error events are now dispatched from the CacheLoader and not his contentLoaderInfo.)
To preload pages, just add the page as a ByteArray asset in your site.xml:
1 | <asset id="page2_cache" src="page.swf" type="bytearray"/> |
The SWF files are cached as ByteArray. Therefore the pages are normally loaded, constructed and destroyed. So there is no need to adjust your pages to make use of this caching mechanism.
Note: use right mouse button to navigate. Page2 is preloaded as bytearray asset.
You can use a proxy tool (like Charles or firebug) to see that all page SWF files are only loaded once. (Note: scaffold.swf is not a page)
These classes will soon be available in our Temple library.


A few weeks ago we launched the new website for We Fashion.
When I saw the
De Match-O-Tron is een project voor Soa Aids Nederland, waarin je kan testen hoe goed je relatie met je partner is. Het doel is om mensen bewust te maken op soa’s en te motiveren een soa-test te gaan doen.
‘Vertel het je familie’ is een project voor T-Mobile ter promotie van ‘T-Mobile family’. Samen met collega’s hebben we dit project in een recordtijd uit de grond gestampt. Met toch wel een erg leuk resultaat.












