- 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.
- The template will be compiled only for the first time, when it invoked, after loading the application files into the browser.
- It is a type of compilation that Runs every time at runtime or compiles our code in the browser at runtime.
- 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.
- It Compiled the code in the browser.
- Each file of application is compiled separately.
- This is suitable for local development.
- If there is any binding error then Template binding errors are shown at the time of application is rendered.
- Loads the application is slower than the AOT compilation. As it need to compile the application code when running it for the first time.
- Bootstrapping or loading app module into the browser is done by “@angular/platform-browser-dynamic” package.
- For JIT compilation following command is use:
ng build
ng serve
- JIT compilation code include the compiler code so its bundle size is heavier.
- Advantage:
- The developer does not need to compile it manually at command prompt (CLI) for each and every modification of application code.
- 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.