The Angular docs specify several reasons for using AOT compilation in favor of JIT:
- Faster rendering
- Fewer asynchronous requests
- Smaller Angular framework download size
- Detect template errors earlier
- Better security
However, when looking for arguments to use JIT I found none. Moreover, after upgrading from Angular 5.2 to Angular 8 I suddenly get a strange error when running a dev build (using JIT). The error is:
ERROR in ./src/app/shared/app-configuration/shared/app-configuration.model.ts 22:16-35
"export 'IMyComponents' was not found in '@mycompany/mypackage'
When running a prod build (using AOT) everything was fine. This surprised me as I never ran into an Angular compilation problem in which the prod build succeeded and the dev build failed.
So my assumption is that JIT is only suitable for development builds (i.e. speed). And adding the --aot flag can be done safely without any problem. Or am I missing something?
You're right, Angular offers 2 ways to bind your application:
Just-in-Time (JIT), which compiles your app in the browser at runtime. (when you run
ng serve
)Ahead-of-Time (AOT), which compiles your app at build time. (when you run
ng serve --aot=true
)As JIT compiles your app at runtime, it can optimize the compilation and only build necessary code. So in development mode, it's common to use JIT to save the time of a full build. The compilation time will be faster using JIT.
AOT optimizes the running speed but the compilation time is longer, thats why it's common to use it in production. AOT will also optimize the size of your application as all files will be compiled before running it.