Search code examples
angularjitangular2-aotangular2-bootstrapping

Angular 2 Bootstrapping Options - AOT vs JIT


Just kick started with Angular 2.

  1. What are the various Bootstrapping options in angular 2?

  2. Why is that when I make a change and refresh the index.html takes little time to retrieve the HTML markups?

  3. Differences between them


Solution

  • There are two options

    1. Dynamic bootstrapping

      • compiler used JIT (Just in Time).
      • dynamically compiles the ts files in the browser.
      • this is the reason the index.html takes little time to retrieve the markups.
      • main.ts contains the following

        import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
        import { AppModule }              from './app.module';
        
        platformBrowserDynamic().bootstrapModule(AppModule);
        
        1. Static bootstrapping
      • compiler used AoT (Ahead of Time).
      • The ts files are compiled into js files and then rendered to the browser.
      • By this, a set of js files containing modules and factories are created there by making them light weight.
      • Mostly used in the case of mobiles and legacy networks.
      • main.ts contains the following

        import { platformBrowser } from '@angular/platform-browser';
        import { AppModuleNgFactory }              from '../aot/app/app.module.ngfactory';
        
        platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
        

    Differences enter image description here