Friday, November 2, 2018

JIT vs AOT compiler in Angular

Angular applications consists of components and service classes written in TypeScript and HTML templates. Browsers cannot understand TypeScript hence they need to be compiled into JavaScript.

Angular provides 2 types of compilers for this compiling process.


1. Just-In-Time (JIT) compiler.
2. Ahead-of-Time (AOT) compiler


JIT compilers does the compilation at runtime in the client’s browser and obviously this is slower. In the JIT complier process the Angular library files are downloaded to the browser, the application files are also downloaded and the compilation happens in the browser. This compilation process takes some time hence it is a bit slower that AOT compilation.

AOT compilers compile the classes and templates at build time converts the TypeScript into JavaScript, bundles the compiled JavaScript and makes it ready for rendering in the browser. When the browser requests for the application the compiled and bundled files are downloaded to the browser and rendered immediately.

Just-In-Compiler is the default Angular compiler used during development phase, the following commands invoke the JIT compiler.

ng build
ng server


The use the Ahead-of-Time AOT compiler we need to use the –aot switch as follows.

ng build --aot
ng server –aot


Production builds with the -–prod switch will use the AOT compiler by default

ng build --prod


Search Flipkart Products:
Flipkart.com

No comments: