Speeding Up Ionic Apps with Lazy-Loaded Angular Modules
Learn how to lazy-load Angular modules in Ionic to shrink the initial bundle and improve startup time.
25 Sept 2026, 04:11 UTC

Problem: Slow Start-up in an Ionic Hybrid App
When you bundle every Angular feature module into the main JavaScript file, the initial download can grow to several megabytes. On a 3G connection this translates to a noticeable white screen before the first screen appears.
Thesis: Use Ionic Router's lazy-loading to split code at the route level
By configuring child routes with loadChildren, Ionic CLI creates separate chunks that are fetched only when the user navigates to that feature. The root module stays small, and the app becomes usable faster.
How Lazy Loading Works in Ionic Angular
- The root
app-routing.module.tsdefines a path like{ path: 'home', loadChildren: () => import('./home/home.module').then(m => m.HomePageModule) }. - During
ionic servethe dev server mimics the same chunk loading, so you can see the request in Chrome DevTools. - Running
ionic build --prod(orionic build --configuration=production) outputs files such asmain.js,home-home-module.jsand source maps.
Worked Example: Adding a Lazy-Loaded Settings Page
- Generate the page:
ionic generate page settings - Open
src/app/app-routing.module.tsand add a child route:
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', loadChildren: () => import('./home/home.module').then(m => m.HomePageModule) },
{ path: 'settings', loadChildren: () => import('./settings/settings.module').then(m => m.SettingsPageModule) },
{ path: '**', redirectTo: 'home' }
];
- Run the dev server:
ionic serve - Open Chrome DevTools → Network, enable 'Disable cache', then click a link that goes to /settings.
- You should see a request for a file similar to
settings-settings-module.js(the exact name contains a hash). - Optional: add
console.log('Settings module loaded');inside the SettingsPage constructor and verify it appears only after navigation.
Trade-off: Initial Navigation Delay
The first visit to a lazy-loaded route incurs a small extra round-trip to fetch the chunk. On a slow network this can add 100-300 ms. Mitigation strategies:
- Pre-load critical chunks with
routerLinkPrefetchor a customGuardthat callsloadChildrenearly. - Keep the lazy modules reasonably sized; avoid putting large libraries inside them unless they are truly needed.
Actionable Closing
Start by profiling your app's main bundle size (ionic build --prod --source-map and inspect www/build). If the main JavaScript exceeds 1 MB, pick a low-traffic feature, convert its route to lazy-loaded using the pattern above, and verify the chunk appears in the Network tab. Repeat until the initial load meets your target performance budget.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.