Angular Performance Boost: trackBy for Efficient List Rendering

Day2/30 || Angular This one small change improved my Angular app performance instantly 🚀 Most Angular developers use *ngFor… but very few optimize it properly 👇 I faced this in a real project where a list was re-rendering again and again — even when data didn’t actually change. 👉 The issue? Angular was recreating DOM elements unnecessarily. By default, Angular tracks items by object reference, not by unique identity. 💡 Here’s the fix: trackBy ——————————————————- Typescript trackById(index: number, item: any): number { return item.id; } —————————————————- HTML <li *ngFor="let item of items; trackBy: trackById"> {{ item.name }} </li> ✅ What this does: • Prevents unnecessary DOM re-rendering • Improves performance for large lists • Keeps UI smooth even with frequent updates 🚀 Real impact: In my case, it reduced UI lag significantly when working with dynamic data. 👉 Takeaway: If your list has a unique ID and you’re not using trackBy… you’re missing a big performance boost. Curious — are you using trackBy in your projects or still relying on default behavior? 🤔 #Angular #FrontendDevelopment #WebPerformance #JavaScript #SoftwareEngineering

Small change, big performance gain. Especially useful in dynamic or frequently updating lists.

To view or add a comment, sign in

Explore content categories