Angular

Performance Optimization

OnPush strategy, trackBy, virtual scrolling, lazy loading, preloading, bundle size, Core Web Vitals, profiling

22 interview questionsยท
Senior
1

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.

2

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.

3

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.

4

Which method to trigger to force a check with OnPush?

5

What is the main advantage of virtual scrolling for large lists?

+19 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free