3gwebtrain
3gwebtrain

Reputation: 15303

app compiler time with `ng serve --aot=true` takes more time than just `ng serve`

I my angular app, i have no.of modules. when i change something with html or css it take time to re-compile. so i decided to start with ng serve --aot=true but I find it take more time to run the app compare to without any flag as ng serve. But what is wrong here or what is the purpose of ng serve --aot=true then?

any one help me to understand the ng serve --aot=true flag.

Upvotes: 1

Views: 1291

Answers (1)

youri
youri

Reputation: 1160

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)

  • Compiled in the browser
  • Each files compiled separately
  • No need to build after changing your code and before reloading the browser page
  • Suitable for local development

Ahead-of-Time (AOT), which compiles your app at build time. (when you run ng serve --aot=true)

  • Compiled by the machine itself, via the command line (Faster)
  • All code compiled together, inlining HTML/CSS in the scripts
  • No need to deploy the compiler
  • Suitable for production builds

The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default.

The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.

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.

Upvotes: 2

Related Questions