1

While reading about AOT in Angular from here, I can across the flow of how actually the .ts files are loaded to browsers. Being new to Angular, I would be really grateful if someone can explain me the inner working of how it all works. I tried to search on google but there are no question where this has been explained.

With angular2, if you go with JIT (which is default), both the compiles happen after the code is loaded in the browser (i.e. TS -> JS -> binary). Not only is it an additional overhead to do the TS -> JS compilation on the fly on the browser, but also, the angular2 compiler is almost half the size of the angular2 package so if we avoid this, we can reduce the size of the payload significantly.

My question against above paragraph:

  1. How does both the compiles happen after the code is loaded in the browser happen ? I mean, do TypeScript compiler does this ?
  2. where does TypeScript compiler resides which converts TS to JS files ? is it on the local dev server ?

Basically I want to know how the ts gets rendered in Angular. I hope it's a good question to be asked on SO.

Samuel
  • 1,128
  • 4
  • 14
  • 34
  • https://angular.io/guide/aot-compiler. JIT vs. AOT has nothing to do with the .ts files compilation. Those are always compiled at build time.The browser doesn't load .ts files. It loads the JS files generated by the TypeScript compiler. The JIT or AOT compiler of Angular is the compiler that compiles the **HTML templates** to JavaScript. – JB Nizet Apr 02 '18 at 10:26
  • See this https://stackoverflow.com/q/48942691/5695162 – Vikas Apr 02 '18 at 10:26
  • 3
    I read the article you linked to. It's completely wrong. Read the official documentation instead. The author doesn't understand what he's talking about. – JB Nizet Apr 02 '18 at 10:50
  • @Vikas: Thank you. Seems to be of great help – Samuel Apr 02 '18 at 13:15
  • @JBNizet: Thanks for your input. I'll refer official docs then. – Samuel Apr 02 '18 at 13:16

0 Answers0