Просто начал с Angular 2.
Каковы различные варианты начальной загрузки в angular 2?
Почему, когда я вношу изменения и обновляю index.html, требуется мало времени для извлечения разметки HTML?
Различия между ними
Просто начал с Angular 2.
Каковы различные варианты начальной загрузки в angular 2?
Почему, когда я вношу изменения и обновляю index.html, требуется мало времени для извлечения разметки HTML?
Различия между ними
Есть два варианта
Динамическая загрузка
main.ts содержит следующее
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
main.ts содержит следующее
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
В Angular есть два способа компиляции
Я хотел бы добавить четыре основных различия, когда дело доходит до компиляции JIT и AOT.
|----------------------------------------|---------------------------------------------|
| JIT | AOT |
|----------------------------------------|---------------------------------------------|
| JIT compilation as the name implies, | AOT compilation compiles the application at |
| compiles the application Just in Time | build time |
| in the browser at runtime | |
|----------------------------------------|---------------------------------------------|
|For JIT compilation the browser needs to| AOT compilation it does not have to |
|download the angular compiler | |
|----------------------------------------|---------------------------------------------|
|While the application is being JIT | With AOT, the application is precompiled |
|compiled in the browser, users have | so there no such wait |
|to wait | |
|----------------------------------------|---------------------------------------------|
|With JIT compilation, the template | With AOT compilation we will come to |
|binding errors are only know at runtime | now about them at build time. |
|----------------------------------------|---------------------------------------------|
По умолчанию следующие 2 команды используют JIT-компиляцию.
ng build
ng serve
С помощью любой из этих команд мы можем использовать параметр - -aot
для включения AOT.
ng build --aot
ngserve --aot
Чтобы отключить ACT для рабочей сборки, установите для параметра - - aot
значение false
.
ng build -- prod --aot false