DEV Community

Cover image for 🧱 “Optimizing Angular Apps for Performance — Real Techniques That Work”
Mridu Dixit
Mridu Dixit

Posted on

🧱 “Optimizing Angular Apps for Performance — Real Techniques That Work”

Even with Angular 20’s latest improvements, many apps still lag, freeze, or load slowly.
The good news? You don’t need a rewrite — just the right performance strategies.

🚀 1. Use OnPush Change Detection

Angular’s default change detection checks everything on each event or async update.
For large apps, that’s a performance killer.

âś… Switch to ChangeDetectionStrategy.OnPush to update components only when inputs change.

@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ProfileComponent {
  @Input() user!: User;
}

Enter fullscreen mode Exit fullscreen mode

Why it works:
It stops Angular from re-checking the entire component tree unnecessarily.

⚡ 2. Leverage Signals for Reactive Updates

In Angular 20, Signals make state updates more predictable and efficient.

Instead of relying on RxJS for simple UI changes:

user = signal<User | null>(null);

loadUser() {
  this.user.set({ name: 'Mridu', age: 28 });
}

Enter fullscreen mode Exit fullscreen mode

Why it’s faster:
Signals trigger only relevant components to re-render — no global change detection needed.

đź§  3. Lazy Load Everything You Can

Don’t load what you don’t need.
Break your app into smaller feature modules and use Angular’s lazy loading.

{
  path: 'dashboard',
  loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
}

Enter fullscreen mode Exit fullscreen mode

Bonus: Combine with route-level preloading for smoother UX.

🪄 4. Optimize Template Rendering

Small template mistakes can slow everything down:

Avoid calling functions directly inside templates:

<!-- Bad -->
<p>{{ calculateTotal() }}</p>

Enter fullscreen mode Exit fullscreen mode

Instead, use precomputed values:

total = this.calculateTotal();

Enter fullscreen mode Exit fullscreen mode
<p>{{ total }}</p>

Enter fullscreen mode Exit fullscreen mode

Why it helps:

Template function calls re-run on every change detection cycle.

đź’ľ 5. Use TrackBy in NgFor

When looping through lists, Angular re-renders every item by default — even unchanged ones.

<li *ngFor="let user of users; trackBy: trackById">{{ user.name }}</li>

Enter fullscreen mode Exit fullscreen mode
trackById(index: number, user: User) {
  return user.id;
}

Enter fullscreen mode Exit fullscreen mode

Result: Only modified list items are updated — the rest stay untouched.

.

đź§° 6. Code Split and Defer Heavy Imports

Large dependencies slow down initial load times.

Use dynamic imports for rarely used modules or libraries:

async openChart() {
  const { Chart } = await import('chart.js');
  // use Chart dynamically
}

Enter fullscreen mode Exit fullscreen mode

📦 7. Bundle Optimization

Use Angular CLI’s built-in power:

ng build --configuration production

Enter fullscreen mode Exit fullscreen mode

This enables:

  • Ahead-of-Time (AOT) compilation
  • Tree shaking
  • Minification and compression

Pro Tip: Check bundle size with

ng build --stats-json
npx source-map-explorer dist/*.js

Enter fullscreen mode Exit fullscreen mode

đź§© 8. Cache Wisely with Service Workers

Use Angular PWA setup to cache assets and API responses.

ng add @angular/pwa

Enter fullscreen mode Exit fullscreen mode

Offline mode + faster reloads = smoother UX.

🔍 9. Audit Regularly

Don’t guess — measure.
Use:

  • Chrome DevTools → Performance tab
  • Lighthouse
  • Angular DevTools

Track FPS, memory usage, and network calls to find bottlenecks.

.

đź’ˇ 10. Bonus: Avoid Overusing RxJS

RxJS is powerful — but misuse leads to subscription leaks and redundant streams.
âś… Use async pipes instead of manual subscriptions.

<p>{{ user$ | async }}</p>

Enter fullscreen mode Exit fullscreen mode

đź§± Final Thoughts

Optimizing Angular isn’t about complex hacks — it’s about smart defaults and mindful architecture.
If you:

  • Use OnPush and Signals
  • Lazy load features
  • Minimize bundle bloat

…you’ll instantly see faster load times, smoother UI, and happier users.

🚀 Small changes. Big difference.
Comment below — what’s your go-to Angular performance trick?

Top comments (0)