Angular 7

Just-In-Time compilation (JIT)

Just-In-Time compilation (JIT)

 

  1. Templates (.html files) files  and angular compiler files will be loaded into the browser and then the templates will be compiled automatically at the time of execution, when the component is invoked.
  2. The template will be compiled only for the first time, when it invoked, after loading the application files into the browser.
  3. It is a type of compilation that Runs every time at runtime or compiles our code in the browser at runtime.
  4. Flow of JIT:
  • At the beginning phase of Angular 2 application when bootstrapped or load in the browser, the JIT compiler performs a lot of work  that is parsing the component templates every time the user opens the web page, a part that transforms HTML templates into runnable code. to analyze the components in the application at runtime and generate code in memory. When the page is refreshed, all the work that has been done is thrown away, and the JIT compiler does the work all over again. This was a major issue that brings to AOT.
  1. It Compiled the code in the browser.
  2. Each file of application is compiled separately.
  3. This is suitable for local development.
  4. If there is any binding error then Template binding errors are shown at the time of application is rendered.
  5. Loads the application is slower than the AOT compilation. As it need to compile the application code when running it for the first time.
  6. Bootstrapping or loading app module into the browser is done by “@angular/platform-browser-dynamic” package.
  7. For JIT compilation following command is use:

ng build

ng serve

  1. JIT compilation code include the compiler code so its bundle size is heavier.
  2. Advantage:
  • The developer does not need to compile it manually at command prompt (CLI) for each and every modification of application code.
  1. Disadvantage:
  • Performance is slower, because every time when we run the application, the templates will be loaded into browser and compiled in the browser at run time. it takes some time to compile.