AOT (Ahead-of-Time) and JIT (Just-in-Time) are two compilation strategies used in Angular.
Ahead-of-Time (AOT) Compilation: In AOT, the Angular application is compiled during the build process and the compiled code is delivered to the browser. The advantage of AOT is that the application runs faster because the compiler has already transformed the code into JavaScript, making it easier for the browser to execute. Additionally, with AOT, the compiler can perform optimizations such as tree-shaking (eliminating unused code) and dead-code elimination. AOT also provides better security by preventing injection attacks, as the compiled code is less susceptible to tampering.
Ahead-of-Time (AOT): Compiles your application and libraries at build time. This is the default starting in Angular 9.
Just-in-Time (JIT) Compilation:
In JIT, the Angular application is compiled in the browser, during runtime.
This means that the application is compiled just before it is executed. The
advantage of JIT is that it is easier to debug because the source code is
available in the browser. Additionally, JIT makes it easier to develop and test
the application, as changes can be made and tested without having to rebuild
the application.
Just-in-Time (JIT): Compiles your application in the browser at runtime. This was the default until Angular 8.
The Angular compiler converts our applications code (HTML and TypeScript) into JavaScript code before browser downloads and runs that code.
1.
JIT compiles our app in the browser at
run-time.
2.
Compiles before running
3.
Each file compiled separately
4.
No need to build after changing our app
code and it automatically reflects the changes in your browser page
5.
Highly secure
6.
Very suitable for local development
AOT (Ahead-of-Time)
-
1.
AOT compiles our app code at build
time.
2.
Compiles while running
3.
Compiled by the machine itself, via the
command line (Faster)
4.
All code compiled together, in-line
HTML/CSS in the scripts
5.
Highly secure
6.
Very suitable for production builds