Here are the reasons to use an AOT compiler in Angular:

  • Faster rendering: Using the AOT compiler, browsers can download a pre-compiled version of the application. This ensures that the browser can render the application immediately using executable code without having to wait for the whole compilation.
  • Less asynchronous requests: Using inline external HTML templates and CSS style sheets within the application, the compiler eliminates separate ajax requests for those specific resource files.
  • Reduced Angular framework download size: There's no need to download the Angular compiler if the app is already compiled. This is very advantageous and efficient as the compiler is almost half the size of Angular, so, not having to add that increases the application payload dramatically.
  • Optimized Error Handling: Detecting existing template errors and reporting template binding errors during the building step before users can see.
  • Enhanced Security: Compilation of HTML templates and other components into JS files before client-side rendering. This reduces the scope for risky JS evaluation or injection attacks. The AOT compiler the HTML templates and other components into JS files before they are served to the client. With no templates to read and no risky client-side JavaScript or HTML evaluation, there are fewer opportunities for injection attacks.
BY Best Interview Question ON 25 Mar 2020