Friday, 28 December 2018

What is AOT (Ahead-of-Time compilation) ?

AOT compilation compiles the application code at build time. By default, the production build is Ahead-of-Time compiled. This means the code is pre-compiled. As angular code is precompiled no need for the browser to download the Angular compiler and compile the code to execute. As compiler code is not downloaded to the browser the network traffic also reduced as the size of the compiled code is very less compared to JIT compiled.  The AOT code is minified, uglified and treeshaked to remove any code that we are not referencing in our application. So the bundler size is further reduced.

With AOT compilation, template binding errors are detected and reported at build time itself as opposed to runtime. 

JIT compiler is the default compiler for Angular. So when we use ng  build or ng serve it uses JIT compiler. To make the code AOT compile we need to instruct with AOT command as below,

ng build --aot
ng serve --aot

Production build uses AOT compiler by default. So we no need to do any extra exercise for this. If you want to turn off AOT for the production build, you can do so by setting --aot option to false,

ng build --prod --aot false





No comments:

Post a Comment