Performance Optimization
Diagnose web performance issues and produce a remediation plan. Stack-agnostic. Anchored to Core Web Vitals and standard browser performance patterns.
This skill goes deeper than the performance checks in qa-testing and seo-technical. Use this when performance itself is the goal.
When to use
- Fixing Core Web Vitals (LCP, INP, CLS)
- Diagnosing slow page loads
- Reducing JavaScript bundle size
- Optimizing images, fonts, and other assets
- Fixing layout shift, render-blocking resources, jank
- Pre-launch performance verification
- Annual performance health check
When NOT to use
- General QA after deploys (use
qa-testing)
- Technical SEO including indexing and crawling (use
seo-technical)
- Code review for general bugs (use
code-review-web)
Required inputs
- The site or page under audit
- Specific performance complaints if any
- Target metrics (Core Web Vitals thresholds, Lighthouse score, custom)
- Browser dev tools access
- Performance monitoring data if available (Real User Monitoring, lab data)
The framework: Core Web Vitals
Three metrics carry most of the weight for both user experience and SEO:
LCP (Largest Contentful Paint)
What it measures: Time until the largest visible content element finishes rendering.
Targets:
- Good: under 2.5 seconds
- Needs improvement: 2.5 to 4.0 seconds
- Poor: over 4.0 seconds
Common causes of poor LCP:
- Slow server response time (TTFB over 800ms)
- Render-blocking JavaScript or CSS
- Large unoptimized images for the LCP element
- Late-loading fonts that delay text render
- Client-side rendering of the LCP element
Common fixes:
- Server-render the LCP element (no client-side render)
- Optimize the LCP image (right format, right size, preloaded)
- Reduce render-blocking resources (defer non-critical CSS and JS)
- Use modern image formats (WebP, AVIF)
- Specify image dimensions to skip layout pass
INP (Interaction to Next Paint)
What it measures: Responsiveness to user interactions. Replaces FID as the standard interactivity metric.
Targets:
- Good: under 200ms
- Needs improvement: 200 to 500ms
- Poor: over 500ms
Common causes of poor INP:
- Long-running JavaScript blocking the main thread
- Heavy event handlers
- Excessive React/framework re-renders
- Synchronous operations in event handlers
- Large DOM with expensive layouts
Common fixes:
- Break long tasks into chunks (
scheduler.yield() or setTimeout)
- Memoize expensive computations
- Debounce or throttle high-frequency event handlers (scroll, mousemove, input)
- Avoid synchronous storage or DOM operations in handlers
- Reduce DOM size (under 1500 elements ideal)
- Use CSS over JS for animations where possible
CLS (Cumulative Layout Shift)
What it measures: How much the page jumps around as it loads. Unexpected layout shifts hurt usability.
Targets:
- Good: under 0.1
- Needs improvement: 0.1 to 0.25
- Poor: over 0.25
Common causes of poor CLS:
- Images without explicit dimensions
- Ads, embeds, iframes that load late
- Dynamically injected content above existing content
- Web fonts causing FOIT/FOUT (flash of invisible/unstyled text)
- CSS that depends on JS-loaded data
Common fixes:
- Always specify
width and height (or aspect-ratio) on images and videos
- Reserve space for ads and embeds before they load
- Use
font-display: optional or font-display: swap thoughtfully
- Avoid injecting content above the fold after initial render
- Preload critical fonts
Beyond Core Web Vitals
Time to First Byte (TTFB)
The server response time. Bad TTFB makes everything else worse.
Targets: under 800ms ideal.
Common causes:
- Slow database queries on the request path
- N+1 query patterns
- Missing caching
- Server geographic distance from users (no CDN)
- Cold starts on serverless
Fixes:
- Cache database queries
- Use a CDN for static and cacheable dynamic content
- Optimize critical-path queries
- Pre-render where possible (SSG, ISR)
- Edge functions for low-latency dynamic content
Bundle size
JavaScript shipped to the browser.
Targets:
- Initial JS under 170KB compressed for typical pages
- Lazy-loaded chunks under 100KB compressed each
Common causes of bloat:
- Importing entire libraries when only one function is used
- Bundling polyfills for modern browsers
- Including dev-only code in production
- Duplicate dependencies (multiple versions of the same library)
- Large client-side state (Redux store snapshots, etc.)
Fixes:
- Tree-shake imports (
import { fn } from 'lib' not import lib from 'lib')
- Code-split per route
- Lazy-load below-the-fold components
- Audit dependencies; replace heavy ones (e.g., moment.js → date-fns or native Intl)
- Build-time bundle analyzer to spot bloat
- Dynamic imports for rarely-used features
Image optimization
Images are typically 60 to 80 percent of page weight.
Best practices:
- Modern formats: WebP everywhere supported, AVIF where supported
- Responsive images:
srcset for different viewport sizes
- Lazy loading:
loading="lazy" for below-the-fold
- Explicit dimensions: prevents CLS
- Right size: don't ship 4000px images for 800px display
- LCP image: preload, never lazy-load
Font loading
Web fonts often delay text render and cause CLS.
Best practices:
- Self-host fonts (avoid third-party blocking)
- Preload critical fonts (
<link rel="preload" as="font">)
- Use
font-display: swap for non-critical fonts
- Subset fonts to remove unused glyphs
- Use variable fonts where possible
- Provide system-font fallback that visually matches
Third-party scripts
Third parties (analytics, ads, chat widgets) often dominate performance budgets.
Audit each:
- Is it required?
- Can it load after page interaction (defer)?
- Can it run from a worker (off main thread)?
- Is the third party itself fast?
- Are there lighter-weight alternatives?
A common pattern: 50 percent of performance issues come from third-party scripts.
Workflow
- Establish a baseline. Lighthouse scan, WebPageTest run, or Real User Monitoring data. Capture current Core Web Vitals.
- Identify the worst offender. LCP, INP, or CLS - which is failing? Focus there first.
- Diagnose specifically. Browser dev tools (Performance tab, Network tab, Coverage tab). Identify the actual cause of the metric failure.
- Plan fixes. Per identified issue, plan a specific change. Estimate impact and effort.
- Implement. One fix at a time where possible. Easier to measure impact.
- Re-measure. After each major fix, re-run Lighthouse and check Real User Monitoring.
- Iterate. Performance is rarely solved in one pass. Plan for ongoing monitoring and fixes.
Tools
Lab tools (run on demand):
- Lighthouse (built into Chrome DevTools)
- PageSpeed Insights (online)
- WebPageTest (online, more configurable)
- Browser Performance tab (deep flame graph analysis)
Field tools (real user data):
- Chrome User Experience Report (CrUX) - public data for any site
- Real User Monitoring (RUM) - your own users (DataDog, New Relic, custom, etc.)
- Search Console Core Web Vitals report
Lab tools are useful for diagnosis. Field tools are the source of truth for what users actually experience.
Failure patterns
- Optimizing without measuring. Performance theater without baseline metrics. Always measure first.
- Optimizing the wrong metric. A great Lighthouse score with bad real-user metrics means your test conditions don't match users.
- Over-optimizing. Spending weeks shaving 10ms off TTFB while CLS is 0.4. Fix the worst offender first.
- Lighthouse-driven optimization only. Lighthouse runs in idealized conditions. Always check field data.
- Single-page optimization. Performance regressions creep in across the codebase. Build performance budgets and CI checks.
- Treating every byte as equal. A render-blocking 100KB script is worse than a deferred 500KB script.
- Bundle size obsession. Bundle size matters, but execution time matters more. A small bundle that takes 5 seconds to parse is worse than a larger bundle that runs fast.
- Ignoring third parties. "It's the analytics tag, not us." Third parties run on your domain in your users' eyes. Own them.
Output format
Default output is a performance report at performance-audit.md.
Structure:
- Executive summary
- Methodology (tools, conditions, sample pages)
- Current state (Core Web Vitals, Lighthouse scores, RUM data)
- Critical issues (Core Web Vitals failures)
- Important issues (sub-optimal but not failing)
- Polish (further-than-required wins)
- Remediation roadmap (sequenced)
- Performance budget recommendations
- Monitoring plan
For complex audits, include:
- Per-page Lighthouse exports
- Bundle analysis output
- Network waterfall screenshots
- Specific code snippets to change
Reference files
references/audit-template.md - Full performance audit report template.
references/optimization-checklist.md - Quick-reference checklist of common optimizations by priority.
references/optimization-playbook.md - Symptom-to-fix playbook for the common Core Web Vitals problems (LCP, INP, CLS).
1---2name: performance-optimization-123description: Diagnose and fix web performance issues including Core Web Vitals (LCP, INP, CLS), bundle size, asset optimization, render performance, and runtime efficiency. Use this skill whenever the user wants to improve page speed, fix Core Web Vitals, optimize assets, reduce bundle size, debug slow renders, or systematically improve a site's performance. Triggers on performance, page speed, Core Web Vitals, LCP, INP, CLS, FID, TTFB, bundle size, code splitting, image optimization, lazy loading, render blocking, slow page, performance audit, Lighthouse score. Also triggers when traffic or conversion is dropping due to perceived slowness.4---5
6# Performance Optimization
7
8Diagnose web performance issues and produce a remediation plan. Stack-agnostic. Anchored to Core Web Vitals and standard browser performance patterns.
9
10This skill goes deeper than the performance checks in `qa-testing` and `seo-technical`. Use this when performance itself is the goal.
11
12---
13
14## When to use
15
16- Fixing Core Web Vitals (LCP, INP, CLS)
17- Diagnosing slow page loads
18- Reducing JavaScript bundle size
19- Optimizing images, fonts, and other assets
20- Fixing layout shift, render-blocking resources, jank
21- Pre-launch performance verification
22- Annual performance health check
23
24## When NOT to use
25
26- General QA after deploys (use `qa-testing`)
27- Technical SEO including indexing and crawling (use `seo-technical`)
28- Code review for general bugs (use `code-review-web`)
29
30---
31
32## Required inputs
33
34- The site or page under audit
35- Specific performance complaints if any
36- Target metrics (Core Web Vitals thresholds, Lighthouse score, custom)
37- Browser dev tools access
38- Performance monitoring data if available (Real User Monitoring, lab data)
39
40---
41
42## The framework: Core Web Vitals
43
44Three metrics carry most of the weight for both user experience and SEO:
45
46### LCP (Largest Contentful Paint)
47
48**What it measures:** Time until the largest visible content element finishes rendering.
49
50**Targets:**
51- Good: under 2.5 seconds
52- Needs improvement: 2.5 to 4.0 seconds
53- Poor: over 4.0 seconds
54
55**Common causes of poor LCP:**
56- Slow server response time (TTFB over 800ms)
57- Render-blocking JavaScript or CSS
58- Large unoptimized images for the LCP element
59- Late-loading fonts that delay text render
60- Client-side rendering of the LCP element
61
62**Common fixes:**
63- Server-render the LCP element (no client-side render)
64- Optimize the LCP image (right format, right size, preloaded)
65- Reduce render-blocking resources (defer non-critical CSS and JS)
66- Use modern image formats (WebP, AVIF)
67- Specify image dimensions to skip layout pass
68
69### INP (Interaction to Next Paint)
70
71**What it measures:** Responsiveness to user interactions. Replaces FID as the standard interactivity metric.
72
73**Targets:**
74- Good: under 200ms
75- Needs improvement: 200 to 500ms
76- Poor: over 500ms
77
78**Common causes of poor INP:**
79- Long-running JavaScript blocking the main thread
80- Heavy event handlers
81- Excessive React/framework re-renders
82- Synchronous operations in event handlers
83- Large DOM with expensive layouts
84
85**Common fixes:**
86- Break long tasks into chunks (`scheduler.yield()` or `setTimeout`)
87- Memoize expensive computations
88- Debounce or throttle high-frequency event handlers (scroll, mousemove, input)
89- Avoid synchronous storage or DOM operations in handlers
90- Reduce DOM size (under 1500 elements ideal)
91- Use CSS over JS for animations where possible
92
93### CLS (Cumulative Layout Shift)
94
95**What it measures:** How much the page jumps around as it loads. Unexpected layout shifts hurt usability.
96
97**Targets:**
98- Good: under 0.1
99- Needs improvement: 0.1 to 0.25
100- Poor: over 0.25
101
102**Common causes of poor CLS:**
103- Images without explicit dimensions
104- Ads, embeds, iframes that load late
105- Dynamically injected content above existing content
106- Web fonts causing FOIT/FOUT (flash of invisible/unstyled text)
107- CSS that depends on JS-loaded data
108
109**Common fixes:**
110- Always specify `width` and `height` (or `aspect-ratio`) on images and videos
111- Reserve space for ads and embeds before they load
112- Use `font-display: optional` or `font-display: swap` thoughtfully
113- Avoid injecting content above the fold after initial render
114- Preload critical fonts
115
116---
117
118## Beyond Core Web Vitals
119
120### Time to First Byte (TTFB)
121
122The server response time. Bad TTFB makes everything else worse.
123
124**Targets:** under 800ms ideal.
125
126**Common causes:**
127- Slow database queries on the request path
128- N+1 query patterns
129- Missing caching
130- Server geographic distance from users (no CDN)
131- Cold starts on serverless
132
133**Fixes:**
134- Cache database queries
135- Use a CDN for static and cacheable dynamic content
136- Optimize critical-path queries
137- Pre-render where possible (SSG, ISR)
138- Edge functions for low-latency dynamic content
139
140### Bundle size
141
142JavaScript shipped to the browser.
143
144**Targets:**
145- Initial JS under 170KB compressed for typical pages
146- Lazy-loaded chunks under 100KB compressed each
147
148**Common causes of bloat:**
149- Importing entire libraries when only one function is used
150- Bundling polyfills for modern browsers
151- Including dev-only code in production
152- Duplicate dependencies (multiple versions of the same library)
153- Large client-side state (Redux store snapshots, etc.)
154
155**Fixes:**
156- Tree-shake imports (`import { fn } from 'lib'` not `import lib from 'lib'`)
157- Code-split per route
158- Lazy-load below-the-fold components
159- Audit dependencies; replace heavy ones (e.g., moment.js → date-fns or native Intl)
160- Build-time bundle analyzer to spot bloat
161- Dynamic imports for rarely-used features
162
163### Image optimization
164
165Images are typically 60 to 80 percent of page weight.
166
167**Best practices:**
168- Modern formats: WebP everywhere supported, AVIF where supported
169- Responsive images: `srcset` for different viewport sizes
170- Lazy loading: `loading="lazy"` for below-the-fold
171- Explicit dimensions: prevents CLS
172- Right size: don't ship 4000px images for 800px display
173- LCP image: preload, never lazy-load
174
175### Font loading
176
177Web fonts often delay text render and cause CLS.
178
179**Best practices:**
180- Self-host fonts (avoid third-party blocking)
181- Preload critical fonts (`<link rel="preload" as="font">`)
182- Use `font-display: swap` for non-critical fonts
183- Subset fonts to remove unused glyphs
184- Use variable fonts where possible
185- Provide system-font fallback that visually matches
186
187### Third-party scripts
188
189Third parties (analytics, ads, chat widgets) often dominate performance budgets.
190
191**Audit each:**
192- Is it required?
193- Can it load after page interaction (defer)?
194- Can it run from a worker (off main thread)?
195- Is the third party itself fast?
196- Are there lighter-weight alternatives?
197
198A common pattern: 50 percent of performance issues come from third-party scripts.
199
200---
201
202## Workflow
203
2041. **Establish a baseline.** Lighthouse scan, WebPageTest run, or Real User Monitoring data. Capture current Core Web Vitals.
2052. **Identify the worst offender.** LCP, INP, or CLS - which is failing? Focus there first.
2063. **Diagnose specifically.** Browser dev tools (Performance tab, Network tab, Coverage tab). Identify the actual cause of the metric failure.
2074. **Plan fixes.** Per identified issue, plan a specific change. Estimate impact and effort.
2085. **Implement.** One fix at a time where possible. Easier to measure impact.
2096. **Re-measure.** After each major fix, re-run Lighthouse and check Real User Monitoring.
2107. **Iterate.** Performance is rarely solved in one pass. Plan for ongoing monitoring and fixes.
211
212---
213
214## Tools
215
216**Lab tools** (run on demand):
217- Lighthouse (built into Chrome DevTools)
218- PageSpeed Insights (online)
219- WebPageTest (online, more configurable)
220- Browser Performance tab (deep flame graph analysis)
221
222**Field tools** (real user data):
223- Chrome User Experience Report (CrUX) - public data for any site
224- Real User Monitoring (RUM) - your own users (DataDog, New Relic, custom, etc.)
225- Search Console Core Web Vitals report
226
227Lab tools are useful for diagnosis. Field tools are the source of truth for what users actually experience.
228
229---
230
231## Failure patterns
232
233- **Optimizing without measuring.** Performance theater without baseline metrics. Always measure first.
234- **Optimizing the wrong metric.** A great Lighthouse score with bad real-user metrics means your test conditions don't match users.
235- **Over-optimizing.** Spending weeks shaving 10ms off TTFB while CLS is 0.4. Fix the worst offender first.
236- **Lighthouse-driven optimization only.** Lighthouse runs in idealized conditions. Always check field data.
237- **Single-page optimization.** Performance regressions creep in across the codebase. Build performance budgets and CI checks.
238- **Treating every byte as equal.** A render-blocking 100KB script is worse than a deferred 500KB script.
239- **Bundle size obsession.** Bundle size matters, but execution time matters more. A small bundle that takes 5 seconds to parse is worse than a larger bundle that runs fast.
240- **Ignoring third parties.** "It's the analytics tag, not us." Third parties run on your domain in your users' eyes. Own them.
241
242---
243
244## Output format
245
246Default output is a performance report at `performance-audit.md`.
247
248Structure:
2491. Executive summary
2502. Methodology (tools, conditions, sample pages)
2513. Current state (Core Web Vitals, Lighthouse scores, RUM data)
2524. Critical issues (Core Web Vitals failures)
2535. Important issues (sub-optimal but not failing)
2546. Polish (further-than-required wins)
2557. Remediation roadmap (sequenced)
2568. Performance budget recommendations
2579. Monitoring plan
258
259For complex audits, include:
260- Per-page Lighthouse exports
261- Bundle analysis output
262- Network waterfall screenshots
263- Specific code snippets to change
264
265---
266
267## Reference files
268
269- [`references/audit-template.md`](references/audit-template.md) - Full performance audit report template.
270- [`references/optimization-checklist.md`](references/optimization-checklist.md) - Quick-reference checklist of common optimizations by priority.
271- [`references/optimization-playbook.md`](references/optimization-playbook.md) - Symptom-to-fix playbook for the common Core Web Vitals problems (LCP, INP, CLS).