Performance Optimization
OnPush strategy, trackBy, virtual scrolling, lazy loading, preloading, bundle size, Core Web Vitals, profiling
1What is the OnPush strategy in Angular?
What is the OnPush strategy in Angular?
Answer
OnPush is a change detection strategy that limits checks to cases where component inputs change by reference or when an internal event triggers. This optimization significantly reduces the number of detection cycles in complex applications. Applying OnPush by default on presentational components is a best practice for improving performance.
2What is the main role of trackBy in an ngFor directive?
What is the main role of trackBy in an ngFor directive?
Answer
trackBy allows Angular to uniquely identify each item in a list, thus avoiding complete DOM recreation during updates. Without trackBy, Angular destroys and recreates all elements even if only one item changed. Using trackBy with a unique identifier significantly improves the performance of dynamic lists.
3What is lazy loading in the context of Angular routing?
What is lazy loading in the context of Angular routing?
Answer
Lazy loading is a deferred module loading technique that only downloads code when the corresponding route is activated. This reduces the initial bundle size and speeds up the first display of the application. Lazy loaded modules are defined with loadChildren in the route configuration.
Which method to trigger to force a check with OnPush?
What is the main advantage of virtual scrolling for large lists?
+19 interview questions
Other Angular interview topics
TypeScript Basics
TypeScript Advanced
Angular Fundamentals
Components & Lifecycle
Services & Dependency Injection
Angular Modules Organization
Angular CLI
Directives & Pipes
Routing & Navigation
Reactive Forms
Template-driven Forms
RxJS Fundamentals
RxJS Operators
HttpClient & API Calls
Basic State Management
Change Detection
Angular Signals
Standalone Components
Angular Unit Testing
End-to-End Testing
Build & Optimization
NgRx Fundamentals
NgRx Advanced
Angular Architecture
Security & Best Practices
Advanced RxJS Patterns
Angular Universal & SSR
Angular Micro-frontends
Master Angular for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free