mozilla-b2g/gaia — pull request #10614 by jrburke (2013-06-25 20:20:11+00:00)
Title: Bug 886446 - [email] Partition card loading, cache initial card HTML for fast startup

1) splits the cards and their associated HTML into separate files. Uses modules and a module loader plugin to associate the HTML to the card JS.

2) the card implementation in mail_common.js now dynamically loads the next card. Cards can implement a `nextCards` array property if the card wants to preload likely next cards. However, the message_list card does not use it to keep up-front load costs smaller.

3) html_cache_restore.js and html_cache.js are used to store a cache of the card HTML that should be used on startup. html_cache_restore.js is the only JS file in the index.html now, to make insertion of the cached content (from cookie storage) as fast as possible. It then dynamically appends the built/mail_app.js file that starts the main JS logic loading.

The HTML cache for a message_list seems to hover around 16KB across 9 cookie segments. With a configured account, it is common for the "time to load" timing to be in the 700-800ms range. Clicking on the UI does not do anything until the back end fully starts up, but the user can scroll through the list of messages while waiting.

4) the email app now has its own Makefile to handle the concatenation of modules and inlining of startup card HTML templates.

There were concerns about dynamically appended CSS causing reflows, so the Makefile also now combines all the CSS into one built/mail.css file. This approach could be scaled back, and use the css.js loader plugin to dynamically load CSS if need be, but the startup feels very fast now, so it may not be needed.

For mail_app.js:

* the firstAccountLoad flag was used because the message slice's atTop does not seem to be true on the very first sync. Without this change, then the user would see the cache of the New Account screen on first cold restart after configuring an account.

* Activity work is delayed until there is a confirmed push for a new card. Since card loading can be async now, it was possible that activity notification could be triggered before the card it uses to detect a configured account showed up in the DOM.

NOTE:

After merging this change, you will likely need to re-run `make install-git-hook` as it changed, to fix an issue with it not correctly using the excluded files list.