brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
web-performance-optimizationOptimize Angular 21.x web application performance including Core Web Vitals, bundle size, lazy loading with @defer, NgOptimizedImage, OnPush+Signals, SSR TransferState, and Angular CLI build optimization. Use when diagnosing slow Angular apps, preparing for Lighthouse audits, or reducing bundle size — always measure with profiling tools before making change…
Independent GitHub snapshot · Automated classification · Original documentation governs
NO PERFORMANCE OPTIMIZATION WITHOUT MEASURING FIRST — run Lighthouse and ng build --stats-json before writing a single optimization
Profile before optimizing. Every change must have a before/after metric. Do not optimize based on guesswork.
Help developers optimize Angular 21.x SPA performance to improve user experience, SEO rankings, and Core Web Vitals scores. This skill provides systematic approaches to measure, analyze, and improve loading speed, runtime performance, and bundle size — all grounded in Angular-native patterns (signals, @defer, NgOptimizedImage, lazy routes, SSR TransferState).
ng build@defer blocksEstablish baseline metrics before touching any code:
ng build --configuration=production --stats-jsonnpx webpack-bundle-analyzer dist/browser/stats.jsonAngular-specific performance bottlenecks to look for:
ChangeDetectionStrategy.Default) triggering excessive re-rendersBehaviorSubject + async pipe causing unnecessary subscriptions instead of signalsngSrc (NgOptimizedImage) missing auto-sizing and LCP hints@defer blocksindex.htmlFocus on highest-impact Angular improvements first:
NgOptimizedImage with priority on LCP image, <link rel="preload"> for fontsloadComponent/loadChildren), @defer for below-fold componentsOnPush + signals on all components, eliminate Default change detectionNgOptimizedImageApply improvements in priority order — measure after each step.
ng build --stats-json — compare bundle sizesSee references/optimization-checklists.md for full worked examples with before/after code and measured results.
@defer, build budgetssharp) + CDN loader configurationng build --stats-json before any optimizationChangeDetectionStrategy.OnPushsignal() and computed() instead of BehaviorSubject + async pipeloadComponent/loadChildren for every feature — nothing should be eagerly imported in app.routes.ts@defer (on viewport) block<img> in Angular templates with ngSrc; never bypass itmaximumWarning: 500kb / maximumError: 1mb in angular.json so CI fails before a bloated build ships<link rel="preload"> for critical fonts; priority attribute on LCP imagedist/browser/ from a CDN with immutable cache headersChangeDetectionStrategy.Default — this is the single largest Angular runtime performance killerindex.ts) in feature modules — they pull in everything, killing tree shaking<script> in index.html; use defer or post-bootstrap dynamic injectionwidth/height on ngSrc images — NgOptimizedImage will throw in dev mode, and CLS will spike in prodSymptoms: Lighthouse passes on desktop, fails on mobile throttling Solution:
@defer triggers that never fire on mobile (e.g., hover-based triggers on touch devices)lighthouse https://yoursite.com --throttling.cpuSlowdownMultiplier=4 --preset=desktop
Symptoms: ng build exits with "ERROR: bundle initial exceeded maximum budget"
Solution:
npx webpack-bundle-analyzer dist/browser/stats.json@deferng build --configuration=production --stats-json
npx webpack-bundle-analyzer dist/browser/stats.json
Symptoms: CLS > 0.1 in Lighthouse, content jumps on load Solution:
ngSrc — NgOptimizedImage requires width/height and enforces them at build time/* Prevent CLS on any image not using NgOptimizedImage */
img {
aspect-ratio: attr(width) / attr(height);
width: 100%;
height: auto;
}
Symptoms: Time to First Byte > 600ms, server HTML arrives late Solution:
TransferState to avoid re-fetching data the server already fetchedwithIncrementalHydration() — defer hydration of below-fold components// app.config.ts
import { provideClientHydration, withIncrementalHydration } from '@angular/platform-browser';
export const appConfig: ApplicationConfig = {
providers: [
provideClientHydration(withIncrementalHydration())
]
};
Symptoms: Network tab shows the same API call twice (once server, once client) Solution: Use TransferState — serialize data on the server, read it on the client without re-fetching
// product.service.ts
import { Injectable, inject, PLATFORM_ID } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TransferState, makeStateKey } from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { Observable, of } from 'rxjs';
import { tap } from 'rxjs/operators';
const PRODUCTS_KEY = makeStateKey<Product[]>('products');
@Injectable({ providedIn: 'root' })
export class ProductService {
private http = inject(HttpClient);
private transferState = inject(TransferState);
private platformId = inject(PLATFORM_ID);
getProducts(): Observable<Product[]> {
if (this.transferState.hasKey(PRODUCTS_KEY)) {
const products = this.transferState.get(PRODUCTS_KEY, []);
this.transferState.remove(PRODUCTS_KEY);
return of(products);
}
return this.http.get<Product[]>('/api/products').pipe(
tap(products => {
if (isPlatformServer(this.platformId)) {
this.transferState.set(PRODUCTS_KEY, products);
}
})
);
}
}
See references/optimization-checklists.md for the full checklist (Angular Architecture, Bundle Size, Images, CSS, Core Web Vitals targets, SSR).
Critical items:
ChangeDetectionStrategy.OnPush on ALL components — no exceptionsloadComponent or loadChildrenpriority attribute; all other ngSrc images do notTransferState used for all SSR API responsesSee references/optimization-checklists.md for full tool list (Measurement, Bundle Analysis, Image Optimization, Monitoring).
ng build --configuration=production --stats-json + npx webpack-bundle-analyzer dist/browser/stats.jsonangular-spa — Angular component scaffolding, lazy routing, and daisyUI stylingangular-best-practices — OnPush, signals, rendering performance, and SSR hydration patternsangular — Angular 21.x core API reference: Signals, @defer, TransferState, incremental hydrationbrowser-testing — Chrome DevTools performance profiling via MCP; record traces, inspect long taskssystematic-debugging — Root-cause methodology for performance regressionson viewport, on idle, on interaction, when)Key principle: Measure before optimizing. ng build --stats-json + webpack-bundle-analyzer takes 2 minutes and reveals exactly where your bundle weight is — every other optimization is guesswork without it.