angular-best-practices

Angular performance optimization and best practices guide. Use when writing, reviewing, or refactoring Angular code for optimal performance, bundle size, and rendering efficiency.

Author

Install

Hot:4

Download and extract to your skills directory

Copy command and send to OpenClaw for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-angular-best-practices&locale=en&source=copy

Angular Best Practices - Angular Performance Optimization and Code Review Guide

Skill Overview

Angular Best Practices is a comprehensive guide for optimizing the performance of Angular applications. It provides prioritized best-practice rules to help developers eliminate performance bottlenecks, reduce bundle sizes, and improve rendering efficiency when writing, reviewing, and refactoring Angular code.

Applicable Scenarios

1. Writing and Developing Angular Components

When developing new Angular components or pages, this guide provides a complete specification covering change detection strategies, state management, and template optimizations. It includes modern Angular best practices such as using the OnPush strategy, Signals reactive programming, and standalone component patterns, ensuring new code is performant from the start.

2. Code Review and Performance Assessment

During team code reviews, this guide can be used as a checklist to identify code patterns that may cause performance issues. It covers common performance pitfalls such as async waterfall problems, unnecessary re-renders, and memory leak risks, making code reviews more systematic and effective.

3. Refactoring and Optimizing Existing Projects

For existing Angular applications that need optimization, the guide offers clear diagnostics and prioritized solutions. From change detection optimizations (highest priority) to memory management (lower priority), it helps teams prioritize tasks by impact to maximize ROI.

Core Features

1. Priority-based Rules Library for Performance

The guide contains 8 categories with over 40 performance optimization rules, ranked by impact into CRITICAL, HIGH, MEDIUM, and LOW-MEDIUM levels. The highest priorities focus on change detection (Signals, OnPush, Zoneless), eliminating async waterfalls, and bundle optimization—areas that most affect Angular app performance. Each rule includes side-by-side correct and incorrect code examples to visually demonstrate best practices.

2. Guidance on Modern Angular Development Patterns

Comprehensively covers best practices for Angular 17+ features, including:

  • New control flow syntax (@if, @for, @empty) replacing structural directives

  • Signals reactive programming model

  • @defer block-level lazy loading

  • Zoneless (no Zone) mode configuration

  • Incremental Hydration strategies
  • 3. SSR and Rendering Performance Optimizations

    For server-side rendering scenarios, the guide provides specialized solutions like TransferState data transfer, incremental hydration configuration, and critical-content-first rendering. For client-side rendering, it includes list-rendering performance techniques such as virtual scroll, trackBy optimizations, and using pure Pipes, ensuring smooth experience in large-list scenarios.

    Frequently Asked Questions

    Where should Angular performance optimization start?

    It’s recommended to start with change detection optimizations, as this is the biggest factor affecting Angular app performance. Specific measures include: enabling OnPush change detection for all components, using Signals instead of mutable properties, and avoiding nested subscriptions that create async waterfalls. These three optimizations yield the most significant performance gains with relatively low implementation cost. After these, consider route lazy loading, dynamic imports of third-party libraries, and other bundle optimizations.

    When should Angular OnPush change detection be used?

    Almost all components should use the OnPush strategy. It is particularly suitable for: presentation-only components (receive inputs and render), components using Signals for state management, and components rendering lists with @for. The only case where the default strategy might be needed is when a component directly mutates object properties internally (not recommended). OnPush combined with Signals enables precise local updates, greatly reducing unnecessary change detection traversals.

    How to choose between Angular Signals and RxJS?

    Signals are better suited for component-local state management and UI reactive updates, offering automatic dependency tracking and no need for manual cleanup. RxJS is better for handling complex async streams, API call chains, and event stream processing. Best practice: use Signals for component state, RxJS for data fetching and complex async logic, and bridge them at component boundaries with toSignal(). The two are complementary, not mutually exclusive.

    Is this guide applicable to older Angular projects?

    The core principles apply to most Angular versions, but some new features (like Signals, new control flow, @defer) require Angular 16+. For older projects, classic optimizations like OnPush, route lazy loading, trackBy, and virtual scroll can still be applied. It’s recommended to upgrade to a version that supports Signals and then gradually migrate to modern reactive patterns.

    Is Zoneless mode ready for production?

    Zoneless is an experimental Angular feature that is maturing rapidly. By removing zone.js async patches, it can reduce bundle size by about 15KB and improve runtime performance. For new projects (Angular 17+), you can try enabling Zoneless mode but must ensure all dependencies and third-party libraries are compatible. For existing production projects, it’s advisable to wait until the feature is more stable before migrating.

    How to detect performance issues in an Angular app?

    Angular DevTools browser extension is the officially recommended performance analysis tool and can visualize change detection cycles and Profiler performance. Common signs of performance problems include: janky list scrolling, bundle size exceeding 1MB, first meaningful paint taking more than 3 seconds, and sustained high CPU usage. The guide’s "quick checklist" provides key points to watch during code reviews and can serve as a starting point for performance health checks.