0
0
Firebasecloud~10 mins

Bundle preloading in Firebase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Bundle preloading
App starts loading
Detect bundles needed
Start preloading bundles
Bundles download in background
Bundles ready when needed
App uses preloaded bundles
Faster app startup and navigation
The app detects which code bundles it will need soon, starts downloading them early in the background, so when the user navigates, the bundles are ready and the app feels faster.
Execution Sample
Firebase
firebase.app().preloadBundles(['bundle1.js', 'bundle2.js']);
// Later when navigating
firebase.app().loadBundle('bundle1.js');
This code tells Firebase to start downloading bundles early, then later loads a bundle instantly from the preloaded cache.
Process Table
StepActionBundleStatusEffect
1App starts-No bundles loadedApp begins loading
2Detect bundles to preloadbundle1.js, bundle2.jsScheduledBundles marked for preloading
3Start preloading bundle1.jsbundle1.jsDownloadingBackground download starts
4Start preloading bundle2.jsbundle2.jsDownloadingBackground download starts
5bundle1.js download completebundle1.jsReadyBundle cached and ready
6bundle2.js download completebundle2.jsReadyBundle cached and ready
7User navigates to feature needing bundle1.jsbundle1.jsLoaded instantlyApp uses preloaded bundle, fast load
8User navigates to feature needing bundle2.jsbundle2.jsLoaded instantlyApp uses preloaded bundle, fast load
9No more bundles to preload--Preloading complete
💡 All bundles preloaded and used, app navigation is faster due to preloading
Status Tracker
VariableStartAfter Step 3After Step 5After Step 7Final
bundle1.js statusNot loadedDownloadingReadyLoaded instantlyLoaded
bundle2.js statusNot loadedDownloadingReadyLoaded instantlyLoaded
preload queueEmptyEmptyEmptyEmptyEmpty
Key Moments - 3 Insights
Why does the app start downloading bundles before the user navigates to them?
Preloading bundles early means they are ready instantly when needed, avoiding waiting time during navigation (see execution_table steps 3-6).
What happens if the user never navigates to a preloaded bundle?
The bundle remains cached but unused, which is a trade-off for faster navigation if used (see execution_table step 9).
How does preloading improve app speed?
Because bundles are downloaded in the background before use, loading them later is instant (see execution_table steps 7-8).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the status of bundle1.js after step 5?
ALoaded instantly
BDownloading
CReady
DNot loaded
💡 Hint
Check the 'Status' column for bundle1.js at step 5 in the execution_table
At which step does the app use the preloaded bundle1.js?
AStep 7
BStep 3
CStep 5
DStep 9
💡 Hint
Look for 'Loaded instantly' status for bundle1.js in the execution_table
If bundle2.js never finishes downloading, what would happen when the user navigates to it?
AIt loads instantly from cache
BApp waits for download to complete
CApp crashes
DBundle is ignored
💡 Hint
Consider the meaning of 'Ready' and 'Downloading' statuses in the execution_table
Concept Snapshot
Bundle Preloading in Firebase:
- Detect bundles needed soon
- Start downloading bundles in background
- Cache bundles when ready
- Load bundles instantly on navigation
- Improves app speed and user experience
Full Transcript
Bundle preloading means the app starts downloading code bundles early, before the user needs them. This way, when the user navigates to a feature, the bundle is already downloaded and loads instantly. The process starts with detecting which bundles will be needed, then downloading them quietly in the background. Once downloaded, bundles are cached and ready. When the user navigates, the app uses the cached bundles, making the app feel faster. If a bundle is never used, it remains cached but unused. This trade-off helps improve app speed and smoothness.