Angular 8.0: Differential Loading and Dynamic Imports for Route Configuration

Optimizing browser bundles. We explore differential loading, dynamic route imports, and CLI tool configurations.

VP
SHIVAM ITCS
·12 April 2019·10 min read·1 views

Technical Overview & Strategic Context

While Angular 6 and 7 improved build configurations, compilation times and bundle sizes remained a challenge for large enterprise applications. The release of Angular 8.0 in mid-2019 addressed this by introducing Differential Loading and dynamic imports for routing. These features optimize package sizes for modern browsers while maintaining compatibility with older browsers, accelerating initial page loading speeds.

Architectural Principle: Use differential loading to serve optimized bundles to modern browsers. Implement dynamic imports for lazy-loaded routes to reduce bundle sizes.

Core Concepts & Architectural Blueprint

Differential loading compiles applications into two sets of bundles: one using ES6 syntax for modern browsers and one using ES5 syntax for older browsers. The browser automatically downloads the appropriate bundle. Additionally, Angular 8.0 adopts standard JavaScript dynamic imports (import()) for lazy-loaded routes, replacing custom string-based path configurations.

Performance & Capability Comparison

Framework FeatureAngular 7.0 StandardAngular 8.0 StandardPerformance Benefit
Differential LoadServes unified ES5 bundles to all browsersServes target ES6/ES5 bundlesReduces bundle sizes in modern browsers
Route ConfigurationsCustom string paths ('./module#Name')Standard dynamic imports (import())Catches routing syntax errors early
Build ToolingVerbose webpack compilation logsConcise CLI build summariesImproves compilation monitoring

Implementation & Code Pattern

To configure lazy-loaded routes using dynamic imports in Angular 8.0, developers should follow these steps:

  • Use dynamic import statements (import()) inside route configuration files.
  • Verify compiler options inside project configurations target ES2015 modules.
  • Remove legacy string-based route paths from configurations.
  • Verify compiled bundle sizes using build analyzers.
typescriptcode
// Route configurations using dynamic imports in Angular 8.0 (2019)
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  {
    path: 'dashboard',
    // Modern dynamic import replaces string-based paths
    loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
  },
  {
    path: 'roster',
    loadChildren: () => import('./roster/roster.module').then(m => m.RosterModule)
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

Operational Governance & Future Outlook

Angular 8.0's introduction of differential loading and dynamic imports optimized package delivery, reducing bundle sizes and page loading times for modern web browsers.

VP
Vijay Paliwal
Founder, SHIVAM ITCS · 18+ years enterprise & AI engineering
MCA · Ex-HiveGPT USA · Ex-Social27 Seattle
Angular 8.0: Differential Loading and Dynamic Imports for Route Configuration | SHIVAM ITCS Blog | SHIVAM ITCS