Lazy‑Loading Feature Modules in Ionic Angular Apps to Cut Startup Bundle Size
Learn how to lazy‑load feature modules in an Ionic Angular app to shrink the initial bundle, speed up startup, and keep navigation smooth.
08 Mar 2026, 19:11 UTC

Problem: Large initial bundle slows hybrid app startup
When an Ionic Angular app bundles every feature module into the main JavaScript file, the first paint can take several seconds on mid‑tier devices. Users see a blank screen or a splash screen while the browser downloads, parses, and executes code they may never need on that visit.
Thesis: Lazy‑loading feature modules with the Angular Router reduces the initial bundle, shortens time‑to‑interactive, and keeps navigation simple.
Ionic’s CLI creates an Angular project where the router is already configured for loadChildren syntax. When a route defines loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule), Angular’s webpack creates a separate chunk that is fetched only when the router navigates to that path. While the chunk loads, ion-router-outlet can show a placeholder such as ion-loading or a custom skeleton.
Worked example: Adding a lazy‑loaded dashboard
- Create a fresh Ionic Angular project (run in a terminal with Node.js ≥18 and Ionic CLI ≥7):
ionic start dashboardDemo blank --type=angular cd dashboardDemo - Generate a feature module that will be lazy‑loaded:
This createsionic generate module features/dashboardsrc/app/features/dashboard/dashboard.module.tsand an empty routing file. - Add a component inside the module to have something to display:
ionic generate component features/dashboard/dashboard - Define the lazy route in
src/app/app-routing.module.ts:const routes: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'home', loadChildren: () => import('./home/home.module').then(m => m.HomeModule) }, { path: 'dashboard', loadChildren: () => import('./features/dashboard/dashboard.module').then(m => m.DashboardModule) }, ]; - Start the dev server:
Open the app ationic servehttp://localhost:8100. Open Chrome DevTools → Network tab, enable "Disable cache". - Verify the initial bundle does not contain dashboard code:
- Reload the page. Look for the main chunk (usually
main.js) and confirm its size does not increase when you add the dashboard module. - Navigate to
/dashboard(e.g., by adding a link in the home page or typing the URL). - Observe a new request for a separate chunk, often named something like
dashboard-module.jsorsrc_app_features_dashboard_dashboard_module_ts.js. The network waterfall shows this chunk being fetched after the navigation. - Optionally, add a temporary
console.log('Dashboard module loaded')inside the dashboard module’s constructor; the log appears only after the route is activated.
- Reload the page. Look for the main chunk (usually
Trade‑off and limitation
The primary trade‑off is a slight navigation delay the first time a lazy module is fetched. On slower networks or low‑end devices this delay can be noticeable, especially if many small modules are lazy‑loaded and each triggers its own request. To mitigate:
- Use a custom preloading strategy that loads critical modules in the background after the app becomes idle.
- Group related features into fewer, larger lazy chunks to reduce request count.
- Show a meaningful placeholder (
ion-loadingor skeleton UI) viaion-router-outletso users perceive progress.
Excessive lazy loading can fragment the experience; profiling with Chrome DevTools’ Performance panel helps decide the right granularity.
Actionable closing
Lazy loading is a low‑effort, high‑impact decision for large Ionic Angular hybrids. Start by identifying features that are not needed on the initial screen, move them into their own modules, and wire them with loadChildren. Verify the split with the network tab, monitor navigation timing, and adjust chunk size based on real‑device testing. This approach keeps the startup bundle lean while preserving the familiar Ionic navigation pattern.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.