Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lazy Loading und Preloading mit Angular, Präsentation von ngGraz, November 2016

Lazy Loading und Preloading mit Angular, Präsentation von ngGraz, November 2016

Manfred Steyer

November 26, 2016
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. About me … • Manfred Steyer • SOFTWAREarchitekt.at • Trainer

    & Consultant • Focus: Angular • Google Developer Expert Page  2 Manfred Steyer
  2. Root Module mit Lazy Loading Page  6 const APP_ROUTE_CONFIG:

    Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'home', component: HomeComponent }, { path: 'flights', loadChildren: './[…]flight-booking.module#FlightBookingModule' } ];
  3. Routen für Feature Module Page  7 const FLUG_ROUTES =

    [ { path: '', component: FlugBuchenComponent, […] }, […] }
  4. Idee • Eventuell später benötigte Module werden nach (!) Anwendungsstart

    geladen • Wird das Modul später tatsächlich benötigt, steht es augenblicklich zur Verfügung Page  11
  5. Preloading aktivieren Page  12 export const AppRoutesModule = RouterModule.forRoot(

    ROUTE_CONFIG, { preloadingStrategy: PreloadAllModules });
  6. Lazy Loading und Shared Modules Page  16 AppModule FlugModule

    SharedModule includes includes (lazy) includes
  7. Lazy Loading und Shared Modules Page  17 AppModule FlugModule

    SharedModule includes includes (lazy) includes AuthService AuthService
  8. Lösung Page  18 AppModule FlugModule SharedModule includes (inkl. Provider)

    includes (lazy) includes (exkl. Provider) AuthService
  9. Shared Module Page  20 @NgModule({ […], providers: [] })

    export class SharedModule { static forRoot(): ModuleWithProviders { return { ngModule: SharedModule, providers: [AuthService, […]] } } }
  10. Zusammenfassung Page  22 Lazy Loading von Modulen webpack splittet

    Bundle Preloading Strategy Shared Modules mit und ohne Provider