heymegabyte/agent-skills / 07-quality-and-verification
quality-and-verification
Unverified5-level verification pyramid: static→unit→Playwright E2E (homepage-first, 6bp)→AI visual→post-deploy. 8-check quality gate. Multi-agent testing (functional/security/a11y/performance). Playwright v1.56+ AI agents (Planner/Generator/Healer, v1.63 current). WCAG 2.2 AA via axe-core v4.13. Percy+Chromatic visual regression. ADA Title II 2027/2028 deadlines.
performance-optimization.md
View on GitHub---
name: "Performance Optimization"
version: "2.0.0"
updated: "2026-04-23"
description: "CWV with LCP 4-phase and INP 3-phase optimization. JS/CSS budgets, image optimization (AVIF/WebP), font loading, preconnect/prefetch, code splitting, tree shaking, compression. 47% of sites pass all three CWV. content-visibility for off-screen."
always-load: false
---
# Performance Optimization
## Core Web Vitals Targets
- **LCP** — Good <2.5s, target **<2.0s**
- **INP** — Good <200ms, target **<100ms**
- **CLS** — Good <0.1, target **<0.05**
## Bundle Budgets
- **Worker script** — 500KB budget, 1MB free / 10MB paid hard limit
- **Initial JS** — 150KB gz budget, 250KB gz hard limit
- **Initial CSS** — 50KB gz budget, 80KB gz hard limit
- **Per-route chunk** — 50KB gz budget, 100KB gz hard limit
- **Total page weight** — 800KB budget, 1.5MB hard limit
- **Hero image** — 100KB budget, 200KB hard limit
- **Web font/family** — 50KB budget, 80KB hard limit
## Image Targets
- WebP photo 80% — <200KB
- AVIF 65% — <150KB (with WebP fallback)
- PNG logo — <50KB
- SVG — <10KB (SVGO)
- OG 1200×630 — <100KB
## Rules
1. Measure before optimizing (Lighthouse + Web Vitals first)
2. Images — WebP/AVIF, correctly sized, lazy below-fold, R2/CDN + cache headers
3. Fonts — `font-display: swap`, preload critical font, self-host from R2
4. JS not needed on first paint — deferred / lazy via dynamic `import()`
5. CSS above-fold inlined, remainder loaded async
6. Every `<img>` — explicit width + height (prevents CLS)
7. Preconnect to critical origins (API, CDN, analytics, fonts)
8. Worker CPU — 10ms avg, 50ms p99
9. Verify tree shaking — inspect output bundle, configure `sideEffects`
10. Compression automatic on CF (Brotli / gzip). Don't double-compress
11. Cache — static `max-age=31536000, immutable` | HTML `max-age=60, s-maxage=3600` | API `private, no-store`
12. No render-blocking third-party scripts (all via GTM async)
## Key Patterns
### Font Loading
```html
<link rel="preload" href="/fonts/space-grotesk-700.woff2" as="font" type="font/woff2" crossorigin>
<!-- font-display: swap, unicode-range: U+0000-00FF (Latin subset) -->
```
### Images
- `<picture>` with AVIF / WebP / fallback
- Above-fold: `loading="eager" fetchpriority="high"`
- Below-fold: `loading="lazy" fetchpriority="low"`
### Resource Hints
- Preconnect critical origins
- `dns-prefetch` less-critical
- `prefetch` next likely nav
### Code Splitting (Angular 22)
Lazy-load routes with `loadComponent: () => import(...)`.
### Worker Timing
Middleware logs `Server-Timing: worker;dur=X` header. Warn if >50ms.
### Cache Headers (Hono)
- `/assets/*` immutable
- HTML short cache + stale-while-revalidate
### Playwright Performance Test
```typescript
test('Core Web Vitals', async ({ page }) => {
await page.goto(PROD_URL);
// Observe LCP + CLS via PerformanceObserver, expect LCP<2500, CLS<0.1
});
```
## LCP Optimization (4 Phases)
1. **TTFB** — edge computing (CF Workers), streaming SSR, CDN aggressive caching
2. **Resource Load Delay** — preload LCP image `fetchpriority="high"`, NEVER lazy-load LCP image (2x slower), never CSS `background-image` for LCP, inline critical CSS
3. **Resource Load Duration** — WebP/AVIF, responsive `srcset`, image CDN
4. **Element Render Delay** — minimize render-blocking, defer non-critical JS, SSR critical content
## INP Optimization (3 Phases)
1. **Input Delay** — break long tasks (>50ms) with `setTimeout` / `requestIdleCallback` / Scheduler API, code splitting, defer non-essential JS
2. **Processing Duration** — lightweight event handlers, debounce/throttle, Web Workers for heavy computation, avoid layout thrashing
3. **Presentation Delay** — reduce DOM size, `content-visibility: auto` for off-screen, virtualize long lists, CSS containment `contain: layout style paint`
## CLS Prevention
- Explicit `width` + `height` on img / video
- `aspect-ratio` CSS
- Reserve space for dynamic content
- `font-display: optional` or `swap` with `size-adjust`
- Preload web fonts
- Never insert content above existing content
## Checklist
- LCP <2.5s on 4G (4-phase optimized)
- INP <200ms (3-phase optimized)
- CLS <0.1
- No render-blocking resources
- `font-display: swap`
- Images WebP/AVIF + lazy + dimensions
- JS <150KB gz
- CSS <50KB gz
- Preconnect critical origins
- Cache headers correct
- Worker CPU <50ms p99
- No layout shifts from dynamic content
- Third-party async via GTM
- `Server-Timing` header
- `content-visibility` on off-screen sections
## Ownership
- **Owns:** CWV measurement, bundle budgets, image optimization, lazy loading, font strategy, resource hints, code splitting, tree shaking, cache headers, Worker CPU monitoring, compression, regression detection
- **Never owns:** Visual design (→10), testing setup (→07), deployment (→08), analytics (→23), SEO (→28), image generation (→12)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |