Search code examples
angularjitangular2-aot

Angular2: Difference between JIT and AOT compiler and which one is better to build angular2 app?


While reading Angular2 doc, I came to know that:

Angular offers two ways to compile your application:

  1. Just-in-Time (JIT), which compiles your app in the browser at runtime
  2. Ahead-of-Time (AOT), which compiles your app at build time.

What are the differences and benefits?


Solution

  • In production, you HAVE to use AOT. JIT makes your server send compiler code as well to the browser and let the client compile your code. This adds overhead at the request and bootstrap time. So, in order to shrink your bundle size and improve performance of your application, you have to use AOT.

    Also, you should always use AOT if you can even in development environment.

    From angular-cli 1.5, you can use --aot option with ng serve. This will provide you an environment like your production, so you will see how your app will behave in production beforehand. Also, since it compiles your code on your server, you catch errors way before you run it on a browser.

    In upcoming versions of Angular-Cli, AOT will be the default option on ng serve.