2

Since I know now, what "angular compiler" actually means, this would be my next question.

I read here about the positive and negative points of ahead of time compiling. To me, it boils down to this:

  • Use AOT for deployments
  • Use JIT for development

The only valid reason (imho) for JIT is, that it runs way faster (which is nice for the development process). Is there any other reason?

AOT has so many HUGE advantages over JIT, that I wonder why JIT is even an option for for a deployment.

codepleb
  • 10,086
  • 14
  • 69
  • 111
  • AOT compiles on build so it doesn't have to do JIT on browser also combined with tree shaking on compile time which can make code optimized and more efficient... – sumeet kumar Oct 10 '17 at 17:43
  • @codepleb, that's the only reason but very strong one. AOT takes too much time to be viable option for development. – Alexander Leonov Oct 10 '17 at 17:50
  • It seems that 'The team is going to make the AOT compilation the default' : https://hackernoon.com/what-to-expect-for-in-angular-v5-6e0fc9c4b13e – Vega Oct 10 '17 at 18:04
  • If you're using token-based authentication, it can cause trouble with AOT because the token is not automatically passed with a GET request and the server can't authenticate or authorize the request. I'm working with this problem right now and we're having to make a lot of less-than-desirable changes to our codebase. – BenWurth Oct 10 '17 at 18:21

1 Answers1

3

Well, There are many difference and some of them are pointed out by you very well. It also dependent what kind of environment you are in and your requirement.

I have been using angular since angular-2.beta.17 when angular cli was not existed and we have to take the help of many build system and run environment to run the project in anywhere.

Systemjs building and running:

In some situation where multiple project and frameworks run together, you can not make a AOT build and bootstrap your code into the SPA and run. In system js environement you have to load the scripts one by one and they bootstrap it.

You must have seen this kind of build and loading script in many online tools like codepen, plunker, etc. I think they all uses systemjs loading

There are many other like commonjs loader, babel build system, webpack build system. But now angular cli is a bullet proof tool with internally use web pack and amber cli to handle everything you want.

Ahead of Time compilation and JIT debugging

As the name suggest AOT do a tree shaking and include everything which is really used in your code and throw away unused codes and compact the code size which can be loaded very fast. But by doing that it looses debugging control and don't give you a nice error message if in case in production you want to see what is wrong.

Same time JIT can point to the line number in typescript file which have the error and make your life super easy to debug while running in dev mode through angular cli.

You can get lot more in angular compiler and there are many tools and games available as well.

one of my favorite is ngrev

Community
  • 1
  • 1
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
  • Yeah, but why is it possible to make a "prod"-deployment without AOT? I don't think that anyone is debugging on production. – codepleb Oct 10 '17 at 19:33
  • if you are using system js loading, you cannot run aot build, you have to manually load dependencies like `@angular/core` etc to execute. so when the application will run in the browser it will compile the execute code rather doing a tree shaking aot build – Aniruddha Das Oct 10 '17 at 20:00