frontend-performance-optimizer
Purpose & When-To-Use
Trigger conditions:
- Core Web Vitals scores below recommended thresholds (LCP >2.5s, FID >100ms, CLS >0.1)
- Page load time exceeds 3 seconds on 3G networks
- JavaScript bundle size >500KB (gzipped)
- User reports of slow initial page render or interaction delays
- Preparing for production launch or performance audit
- Investigating performance regression after deployment
Use this skill when you need systematic frontend performance analysis and actionable optimization recommendations based on industry-standard metrics.
Pre-Checks
Time normalization:
NOW_ET = "2025-12-15T19:35:37-05:00" # NIST/time.gov semantics
Input validation:
- Application URL is accessible or codebase path exists
- Framework type is specified or detectable from package.json/file structure
- If bundle analyzer output provided, verify JSON format validity
- Web Vitals measurement tools available (Lighthouse CLI, WebPageTest API access)
Source freshness:
- Web Vitals thresholds: accessed 2025-12-15 (refresh if >90 days)
- Browser support data: caniuse.com accessed within 30 days
- Framework-specific optimization guides: accessed within 90 days
Procedure
T1: Fast Path (≤2k tokens, 80% of requests)
Goal: Quick performance assessment with high-impact recommendations.
Steps:
Measure Core Web Vitals using Lighthouse or WebPageTest API
- Extract LCP, FID (or INP), CLS scores
- Identify if any metric fails "Good" threshold
Analyze bundle size (if build artifacts available)
- Check total JavaScript size (target: <500KB gzipped)
- Identify largest chunks
Generate top 3 recommendations based on worst metrics:
- LCP issues → image optimization, resource preloading, server response time
- FID/INP issues → reduce JavaScript execution time, code splitting
- CLS issues → explicit size attributes, font loading strategy
Output: Performance score summary + prioritized 3-item action list.
Abort conditions: URL unreachable, no performance data available.
T2: Extended Analysis (≤6k tokens, 15% of requests)
Goal: Comprehensive audit with framework-specific optimizations.
Steps:
All T1 steps plus detailed metric breakdown
Framework-specific analysis:
- React: Check React.lazy usage, code splitting at route level, memo/useCallback patterns
- Vue: Analyze async components, dynamic imports, keep-alive usage
- Angular: Review lazy loading modules, AOT compilation, tree-shaking effectiveness
Resource optimization:
- Image audit: format (WebP/AVIF), sizing, lazy loading, responsive images
- Font strategy: font-display, preload, variable fonts
- CSS: unused styles, critical CSS extraction
Caching strategy review:
- Service worker implementation
- Cache-Control headers for static assets
- CDN configuration (if applicable)
Performance budget definition:
- Set thresholds for JavaScript, CSS, images, total page weight
- Recommend CI integration (Lighthouse CI, bundlesize)
Output: Detailed audit report + code examples + performance budget config.
T3: Deep Dive (≤12k tokens, 5% of requests)
Goal: Root cause analysis with custom optimizations and benchmarking.
Steps:
All T2 steps plus root cause investigation
Waterfall analysis:
- Request chain dependencies
- Render-blocking resources
- Third-party script impact
JavaScript execution profiling:
- Long tasks (>50ms) identification
- Main thread blocking analysis
- Heavy computation offloading opportunities (Web Workers)
Custom optimization strategies:
- Component-level lazy loading (intersection observer patterns)
- Resource hints (preconnect, dns-prefetch, prefetch)
- Module federation for micro-frontends
Benchmarking plan:
- Synthetic monitoring setup (Lighthouse CI)
- Real User Monitoring (RUM) integration
- A/B testing framework for optimization validation
Output: Root cause analysis + custom optimization plan + monitoring setup guide.
Decision Rules
Tier escalation:
- T1 → T2: User requests framework-specific recommendations OR bundle size >1MB
- T2 → T3: Performance regression investigation OR custom optimization needed OR micro-frontend architecture
Ambiguity thresholds:
- Cannot measure Web Vitals (no URL, blocked by auth): Request staging URL or Lighthouse JSON export
- Framework not detected: Ask user to specify or analyze as vanilla JavaScript
- Bundle analyzer unavailable: Provide generic code splitting guidance, recommend webpack-bundle-analyzer setup
Abort conditions:
- URL returns 403/404/500 and no alternative provided
- No build artifacts and no URL (cannot analyze)
- User requests backend optimization (out of scope)
Output Contract
Required fields:
interface PerformanceReport {
metrics: {
lcp: { value: number; rating: "good" | "needs-improvement" | "poor" };
fid: { value: number; rating: "good" | "needs-improvement" | "poor" };
cls: { value: number; rating: "good" | "needs-improvement" | "poor" };
};
recommendations: Array<{
priority: "high" | "medium" | "low";
category: "images" | "javascript" | "css" | "caching" | "fonts" | "third-party";
issue: string;
solution: string;
estimatedImpact: string; // e.g., "0.5s LCP improvement"
codeExample?: string;
}>;
performanceBudget?: {
javascript: string; // e.g., "500KB"
css: string;
images: string;
total: string;
};
nextSteps: string[];
}
Format: Structured JSON or Markdown report with code blocks.
Constraints:
- Code examples ≤30 lines
- Recommendations ranked by estimated impact
- All metrics include rating against Web Vitals thresholds
Examples
Example 1: T1 Quick Audit
Input:
URL: https://example.com/app
Framework: React
Output:
## Performance Audit Summary
**Core Web Vitals:**
- LCP: 4.2s (poor) — Target: <2.5s
- FID: 85ms (good)
- CLS: 0.15 (needs improvement) — Target: <0.1
**Top 3 Recommendations:**
1. **HIGH: Optimize hero image (3.5MB PNG)**
- Convert to WebP/AVIF
- Use responsive images with srcset
- Estimated impact: 1.5s LCP improvement
2. **HIGH: Reduce layout shift in header**
- Add explicit width/height to logo
- Reserve space for dynamic content
- Estimated impact: 0.12 CLS reduction
3. **MEDIUM: Enable text compression**
- Configure gzip/brotli for text assets
- Estimated impact: 0.3s LCP improvement
Quality Gates
Token budgets:
- T1 procedure + output: ≤2k tokens (measured via tiktoken cl100k_base)
- T2 procedure + output: ≤6k tokens
- T3 procedure + output: ≤12k tokens
Safety:
- No execution of user code (analysis only)
- Read-only access to public URLs
- No storage of user content beyond session
Auditability:
- All recommendations cite Web Vitals or framework docs
- Metric thresholds sourced from https://web.dev/vitals/ (accessed 2025-12-15)
- Tool versions specified in output (Lighthouse v11.x, webpack v5.x)
Determinism:
- Same URL + framework → consistent recommendations (within tool variance)
- Performance scores may vary ±5% due to network/server conditions
- Note measurement conditions (device type, throttling) in report
Resources
Official Documentation:
Tools:
Performance Budgets:
1---2name: frontend-performance-optimizer3description: Analyzes and optimizes frontend performance using Core Web Vitals, bundle analysis, lazy loading, image optimization, and caching strategies4license: MIT5---67# frontend-performance-optimizer89## Purpose & When-To-Use1011**Trigger conditions:**1213- Core Web Vitals scores below recommended thresholds (LCP >2.5s, FID >100ms, CLS >0.1)14- Page load time exceeds 3 seconds on 3G networks15- JavaScript bundle size >500KB (gzipped)16- User reports of slow initial page render or interaction delays17- Preparing for production launch or performance audit18- Investigating performance regression after deployment1920**Use this skill when** you need systematic frontend performance analysis and actionable optimization recommendations based on industry-standard metrics.2122## Pre-Checks2324**Time normalization:**25```python26NOW_ET = "2025-12-15T19:35:37-05:00" # NIST/time.gov semantics27```2829**Input validation:**3031- Application URL is accessible or codebase path exists32- Framework type is specified or detectable from package.json/file structure33- If bundle analyzer output provided, verify JSON format validity34- Web Vitals measurement tools available (Lighthouse CLI, WebPageTest API access)3536**Source freshness:**3738- Web Vitals thresholds: accessed 2025-12-15 (refresh if >90 days)39- Browser support data: caniuse.com accessed within 30 days40- Framework-specific optimization guides: accessed within 90 days4142## Procedure4344### T1: Fast Path (≤2k tokens, 80% of requests)4546**Goal:** Quick performance assessment with high-impact recommendations.4748**Steps:**49501. **Measure Core Web Vitals** using Lighthouse or WebPageTest API51 - Extract LCP, FID (or INP), CLS scores52 - Identify if any metric fails "Good" threshold53542. **Analyze bundle size** (if build artifacts available)55 - Check total JavaScript size (target: <500KB gzipped)56 - Identify largest chunks57583. **Generate top 3 recommendations** based on worst metrics:59 - LCP issues → image optimization, resource preloading, server response time60 - FID/INP issues → reduce JavaScript execution time, code splitting61 - CLS issues → explicit size attributes, font loading strategy6263**Output:** Performance score summary + prioritized 3-item action list.6465**Abort conditions:** URL unreachable, no performance data available.6667### T2: Extended Analysis (≤6k tokens, 15% of requests)6869**Goal:** Comprehensive audit with framework-specific optimizations.7071**Steps:**72731. **All T1 steps** plus detailed metric breakdown74752. **Framework-specific analysis:**76 - React: Check React.lazy usage, code splitting at route level, memo/useCallback patterns77 - Vue: Analyze async components, dynamic imports, keep-alive usage78 - Angular: Review lazy loading modules, AOT compilation, tree-shaking effectiveness79803. **Resource optimization:**81 - Image audit: format (WebP/AVIF), sizing, lazy loading, responsive images82 - Font strategy: font-display, preload, variable fonts83 - CSS: unused styles, critical CSS extraction84854. **Caching strategy review:**86 - Service worker implementation87 - Cache-Control headers for static assets88 - CDN configuration (if applicable)89905. **Performance budget definition:**91 - Set thresholds for JavaScript, CSS, images, total page weight92 - Recommend CI integration (Lighthouse CI, bundlesize)9394**Output:** Detailed audit report + code examples + performance budget config.9596### T3: Deep Dive (≤12k tokens, 5% of requests)9798**Goal:** Root cause analysis with custom optimizations and benchmarking.99100**Steps:**1011021. **All T2 steps** plus root cause investigation1031042. **Waterfall analysis:**105 - Request chain dependencies106 - Render-blocking resources107 - Third-party script impact1081093. **JavaScript execution profiling:**110 - Long tasks (>50ms) identification111 - Main thread blocking analysis112 - Heavy computation offloading opportunities (Web Workers)1131144. **Custom optimization strategies:**115 - Component-level lazy loading (intersection observer patterns)116 - Resource hints (preconnect, dns-prefetch, prefetch)117 - Module federation for micro-frontends1181195. **Benchmarking plan:**120 - Synthetic monitoring setup (Lighthouse CI)121 - Real User Monitoring (RUM) integration122 - A/B testing framework for optimization validation123124**Output:** Root cause analysis + custom optimization plan + monitoring setup guide.125126## Decision Rules127128**Tier escalation:**129130- T1 → T2: User requests framework-specific recommendations OR bundle size >1MB131- T2 → T3: Performance regression investigation OR custom optimization needed OR micro-frontend architecture132133**Ambiguity thresholds:**134135- Cannot measure Web Vitals (no URL, blocked by auth): Request staging URL or Lighthouse JSON export136- Framework not detected: Ask user to specify or analyze as vanilla JavaScript137- Bundle analyzer unavailable: Provide generic code splitting guidance, recommend webpack-bundle-analyzer setup138139**Abort conditions:**140141- URL returns 403/404/500 and no alternative provided142- No build artifacts and no URL (cannot analyze)143- User requests backend optimization (out of scope)144145## Output Contract146147**Required fields:**148149```typescript150interface PerformanceReport {151 metrics: {152 lcp: { value: number; rating: "good" | "needs-improvement" | "poor" };153 fid: { value: number; rating: "good" | "needs-improvement" | "poor" };154 cls: { value: number; rating: "good" | "needs-improvement" | "poor" };155 };156 recommendations: Array<{157 priority: "high" | "medium" | "low";158 category: "images" | "javascript" | "css" | "caching" | "fonts" | "third-party";159 issue: string;160 solution: string;161 estimatedImpact: string; // e.g., "0.5s LCP improvement"162 codeExample?: string;163 }>;164 performanceBudget?: {165 javascript: string; // e.g., "500KB"166 css: string;167 images: string;168 total: string;169 };170 nextSteps: string[];171}172```173174**Format:** Structured JSON or Markdown report with code blocks.175176**Constraints:**177178- Code examples ≤30 lines179- Recommendations ranked by estimated impact180- All metrics include rating against Web Vitals thresholds181182## Examples183184### Example 1: T1 Quick Audit185186**Input:**187```188URL: https://example.com/app189Framework: React190```191192**Output:**193```markdown194## Performance Audit Summary195196**Core Web Vitals:**197- LCP: 4.2s (poor) — Target: <2.5s198- FID: 85ms (good)199- CLS: 0.15 (needs improvement) — Target: <0.1200201**Top 3 Recommendations:**2022031. **HIGH: Optimize hero image (3.5MB PNG)**204 - Convert to WebP/AVIF205 - Use responsive images with srcset206 - Estimated impact: 1.5s LCP improvement2072082. **HIGH: Reduce layout shift in header**209 - Add explicit width/height to logo210 - Reserve space for dynamic content211 - Estimated impact: 0.12 CLS reduction2122133. **MEDIUM: Enable text compression**214 - Configure gzip/brotli for text assets215 - Estimated impact: 0.3s LCP improvement216```217218## Quality Gates219220**Token budgets:**221222- T1 procedure + output: ≤2k tokens (measured via tiktoken cl100k_base)223- T2 procedure + output: ≤6k tokens224- T3 procedure + output: ≤12k tokens225226**Safety:**227228- No execution of user code (analysis only)229- Read-only access to public URLs230- No storage of user content beyond session231232**Auditability:**233234- All recommendations cite Web Vitals or framework docs235- Metric thresholds sourced from https://web.dev/vitals/ (accessed 2025-12-15)236- Tool versions specified in output (Lighthouse v11.x, webpack v5.x)237238**Determinism:**239240- Same URL + framework → consistent recommendations (within tool variance)241- Performance scores may vary ±5% due to network/server conditions242- Note measurement conditions (device type, throttling) in report243244## Resources245246**Official Documentation:**247248- [Web Vitals](https://web.dev/vitals/) — Core metrics and thresholds249- [Lighthouse Performance Scoring](https://developer.chrome.com/docs/lighthouse/performance/performance-scoring/) — Audit methodology250- [React Code Splitting](https://react.dev/reference/react/lazy) — Framework-specific optimization251- [Next.js Image Optimization](https://nextjs.org/docs/pages/building-your-application/optimizing/images) — Modern image handling252253**Tools:**254255- [webpack Bundle Analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) — Bundle visualization256- [Lighthouse CI](https://github.com/GoogleChrome/lighthouse-ci) — Automated auditing257- [WebPageTest](https://www.webpagetest.org/) — Detailed waterfall analysis258- [Chrome DevTools Coverage](https://developer.chrome.com/docs/devtools/coverage/) — Unused code detection259260**Performance Budgets:**261262- [Performance Budget Calculator](https://www.performancebudget.io/) — Budget recommendations263- [bundlesize](https://github.com/siddharthkp/bundlesize) — CI integration for size tracking