Performance: Bootstrapping with standalone
This affects the initial page load speed and rendering time by simplifying the app startup process.
Jump into concepts and practice - no test required
import { bootstrapApplication } from '@angular/platform-browser'; import { AppComponent } from './app.component'; bootstrapApplication(AppComponent);
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule], bootstrap: [AppComponent] }) export class AppModule {} platformBrowserDynamic().bootstrapModule(AppModule);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| NgModule bootstrapping | Moderate (due to module metadata) | Multiple (due to delayed rendering) | Higher (longer blocking) | [X] Bad |
| Standalone component bootstrapping | Minimal (direct component) | Single or none | Lower (faster first paint) | [OK] Good |
bootstrapApplication in Angular with standalone components?bootstrapApplicationAppComponent?bootstrapApplication to start apps with standalone components.bootstrapApplication(AppComponent); to bootstrap the standalone component.import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
standalone: true,
template: `Hello Angular!
`
})
export class AppComponent {}
bootstrapApplication(AppComponent);AppComponent has a template with <h1>Hello Angular!</h1>.bootstrapApplication with a standalone component renders its template as the root content.import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `Welcome!
`
})
export class AppComponent {}
bootstrapApplication(AppComponent);standalone: true, which is required for standalone bootstrapping.bootstrapApplication.providers option in bootstrapApplication.bootstrapApplication makes them app-wide.