skill-web-performance
Skill0 starsChanged 3 months agoMITView on GitHub
Universal web performance engineering, Core Web Vitals optimization (LCP, INP, CLS, TBT, TTFB), Lighthouse 100/100 audits, runtime tracing via MCP, asset pipelines, and zero-shift rendering. Use when asked to optimize website performance, improve page speed, fix Core Web Vitals, reduce bundle size, eliminate layout shifts, or conduct performance audits.
In this repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- templates/AGENTS.mdAGENTS.md
- core/CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- avoid-ai-writingSkill
- c-cpp-systemsSkill
- doubt-driven-developmentSkill
- marketing-copywritingSkill
- mempalace-recallSkill
- mempalaceSkill
- mempalace-taskSkill
- retro-emulation-engineeringSkill
- seo-optimization-and-auditSkill
- skill-ai-mlSkill
- skill-backend-architectSkill
- skill-codebase-onboardingSkill
- skill-code-reviewSkill
- skill-context-engineeringSkill
- skill-creative-designSkill
- skill-data-analysisSkill
- skill-data-scienceSkill
- skill-design-engineeringSkill
- skill-devops-cloudSkill
- skill-emulator-wasmSkill
- skill-frontend-architectSkill
- skill-graph-analyticsSkill
- skill-graphics-webglSkill
- skill-low-level-programmingSkill
- skill-master-orchestratorSkill
- skill-mcp-builderSkill
- skill-monorepo-architectSkill
- skill-osint-engineeringSkill
- skill-plugin-architectureSkill
- skill-qa-engineerSkill
- skill-researchSkill
- skill-resume-tailorSkill
- skill-stealth-scrapingSkill
- skill-system-diagnosticsSkill
- skill-web-architectureSkill
- spec-driven-developmentSkill
- spec-minerSkill
- wasm-emscriptenSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 6 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Every production web application must meet or exceed these thresholds measured on Mid-Tier Mobile (Slow 4G + 4x CPU Throttling) and Desktop …
- Very specific: line 56
Never lazy-load the LCP element (never set loading="lazy" on above-fold hero images).
- Very specific: line 57
Ensure the LCP element exists in the raw server HTML payload (avoid client-side useEffect data fetching).
- Very specific: line 60
Use responsive srcset and accurate sizes so mobile devices download appropriately scaled images.
- Very specific: line 112
Every <img>, <video>, <iframe>, and <canvas> must define explicit width/height or CSS aspect-ratio: width / height.
- Very specific: line 114
When using custom web fonts with font-display: swap, configure @font-face metric descriptors on fallback fonts to match the exact x-height …
- Very specific: line 142
Avoid import { Button } from '@/components' if it pulls 50 unused components into the bundle.
- Very specific: line 143
Use direct subpath imports or ensure build bundler supports Turbopack/Tree-shaking with "sideEffects": false.
- Very specific: line 164
Never use JavaScript requestAnimationFrame loops for static background decorations or layout properties (top, left, width, height).
- Very specific: line 173
Use next/font/google or self-hosted WOFF2 with font-display: swap and explicit subsets: ['latin'].
- Distinctive: line 187
When conducting performance optimization on any codebase or URL, follow this deterministic cycle:
- Very specific: line 197
Call lighthouse-mcp (or run npx lighthouse <URL> --output=json --preset=desktop/mobile) to capture standard scores across Performance, …
- Very specific: line 199
Use chrome-devtools tool performance_start_trace to record real page load under 4x CPU Throttling and Slow 4G network.
- Very specific: line 200
Call performance_analyze_insight with insightName: "LCPBreakdown" and insightName: "DocumentLatency".
- Distinctive: line 204
LCP: Check hero image discovery, preload priority, CSS blocking time.
- Distinctive: line 211
Follow strict Single Source of Truth (SSOT) and zero-workaround protocol.
- Distinctive: line 216
If performance score < 100, repeat Phase 2 with specific remaining issues.
- Distinctive: line 240
Before concluding any web performance task:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Web Performance & Core Web Vitals Engineering Skill
This skill provides comprehensive, battle-tested architectural guidelines and an autonomous agentic optimization workflow to achieve elite performance scores (Lighthouse 100/100, Core Web Vitals "Good" at 75th percentile) across modern web platforms (Next.js, Astro, Vite/React, SvelteKit, Vanilla Web).
1. Core Web Vitals & Performance Budgets (2026 Standards)
Every production web application must meet or exceed these thresholds measured on Mid-Tier Mobile (Slow 4G + 4x CPU Throttling) and Desktop Broadband:
| Metric | Full Name | Focus Area | Elite Target | Good (Pass) | Needs Improvement | Poor |
| LCP | Largest Contentful Paint | Loading Speed | ≤ 1.2s | ≤ 2.5s | 2.5s – 4.0s | > 4.0s |
| INP | Interaction to Next Paint | Responsiveness | ≤ 50ms | ≤ 200ms | 200ms – 500ms | > 500ms |
| CLS | Cumulative Layout Shift | Visual Stability | 0.000 | ≤ 0.10 | 0.10 – 0.25 | > 0.25 |
| TBT | Total Blocking Time | Main Thread Load | ≤ 50ms | ≤ 200ms | 200ms – 600ms | > 600ms |
| TTFB | Time to First Byte | Backend & Edge | ≤ 150ms | ≤ 800ms | 800ms – 1800ms | > 1800ms |
| FCP | First Contentful Paint | Perceived Speed | ≤ 0.8s | ≤ 1.8s | 1.8s – 3.0s | > 3.0s |
Hard Resource Budgets (Initial Page Load)
- Compressed JavaScript (Gzip/Brotli): ≤ 150 KB (Hard limit: 300 KB).
- Compressed CSS: ≤ 30 KB (Hard limit: 100 KB).
- Above-the-Fold Critical Assets (Images/Fonts): ≤ 350 KB.
- Total Initial Page Weight: ≤ 1.2 MB.
- Third-Party Script Weight: ≤ 100 KB (Deferred or Web-Worker offloaded).
2. The 7 Pillars of High-Performance Web Engineering
Pillar 1: Critical Rendering Path & Server Latency (TTFB)
- Edge CDN Delivery: Cache HTML and immutable assets at the CDN edge (Cloudflare, Vercel Edge, Fastly).
- HTTP/2 & HTTP/3 Protocol: Enforce multiplexed connections to eliminate connection handshake overhead.
- HTTP 103 Early Hints: Emit
103 Early HintswithLink: </lcp.webp>; rel=preload; as=imageand critical styles while the origin server prepares the200 OKresponse. - Preconnect Optimization: Restrict
<link rel="preconnect">strictly to the top 2-3 essential cross-origin domains (e.g. font CDNs or analytics endpoints). Always pair withcrossoriginwhere needed.
<!-- Critical Preconnects in <head> -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>Pillar 2: LCP Optimization (Largest Contentful Paint)
LCP is broken down into 4 distinct phases: $$\text{Total LCP} = \text{TTFB} + \text{Resource Load Delay} + \text{Resource Load Duration} + \text{Element Render Delay}$$
- Eliminate Resource Load Delay (≤ 10% of LCP):
- Preload the LCP asset in
<head>withfetchpriority="high". - Never lazy-load the LCP element (never set
loading="lazy"on above-fold hero images). - Ensure the LCP element exists in the raw server HTML payload (avoid client-side
useEffectdata fetching).
- Preload the LCP asset in
- Eliminate Resource Load Duration (≤ 40% of LCP):
- Format hierarchy: AVIF (preferred) → WebP → optimized SVG/PNG.
- Use responsive
srcsetand accuratesizesso mobile devices download appropriately scaled images.
- Eliminate Element Render Delay (≤ 10% of LCP):
- Inline Critical Path CSS (< 14 KB) directly into
<head>. - Defer non-critical stylesheets.
- Inline Critical Path CSS (< 14 KB) directly into
- Speculation Rules API (Zero LCP for Next Navigations):
- Prerender high-confidence navigation links on hover:
<script type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>Pillar 3: INP & Main Thread Optimization (Interaction to Next Paint)
Total INP consists of: Input Delay + Processing Duration + Presentation Delay.
- Yielding to the Main Thread:
- Break long synchronous loops (> 50ms) into discrete chunks using
scheduler.yield():
- Break long synchronous loops (> 50ms) into discrete chunks using
async function processBatchedTasks<T>(items: T[], processFn: (item: T) => void) {
const CHUNK_SIZE = 50;
for (let i = 0; i < items.length; i += CHUNK_SIZE) {
const chunk = items.slice(i, i + CHUNK_SIZE);
chunk.forEach(processFn);
if ('scheduler' in window && 'yield' in (window as any).scheduler) {
await (window as any).scheduler.yield();
} else {
await new Promise(resolve => setTimeout(resolve, 0));
}
}
}- Web Worker Offloading: Offload heavy computations, JSON parsing, crypto, and telemetry tracking off the UI thread via
WorkerorPartytown. - Prevent Layout Thrashing: Batch DOM reads (
element.offsetWidth,getBoundingClientRect()) before performing DOM writes (element.style.transform). - React Transitions: Wrap non-urgent state updates in
React.startTransition()oruseDeferredValue().
Pillar 4: CLS (Cumulative Layout Shift) & Visual Stability
Target score: 0.000. Layout shifts damage user trust and search rankings.
- Explicit Dimensions & Aspect Ratios:
- Every
<img>,<video>,<iframe>, and<canvas>must define explicitwidth/heightor CSSaspect-ratio: width / height.
- Every
- Zero-Shift Font Metric Overrides:
- When using custom web fonts with
font-display: swap, configure@font-facemetric descriptors on fallback fonts to match the exact x-height and ascent/descent of the web font:
- When using custom web fonts with
@font-face {
font-family: 'Inter Fallback';
src: local('Arial');
ascent-override: 90%;
descent-override: 22.5%;
line-gap-override: 0%;
size-adjust: 107%;
}(Or leverage Next.js next/font/google which injects these adjustments automatically).
3. Server-Cookie Layout State:
- For collapsible banners, announcement bars, or theme switches, read the state server-side from HTTP cookies before rendering the initial HTML to prevent client-side hydration layout popping.
- Reserved Dynamic Containers:
- Reserve space for dynamic content (advertisements, async data widgets) using CSS
min-heightand skeleton placeholding.
- Reserve space for dynamic content (advertisements, async data widgets) using CSS
Pillar 5: JavaScript & Bundle Architecture
- Dynamic Code Splitting:
- Route-based splitting (
next/dynamic,React.lazy). - Component-based splitting for heavy modals, charts, and drawer drawers.
- Route-based splitting (
- Interaction-Gated Heavy Asset Loading:
- Heavy libraries (Three.js, WebGL shaders, Lucide heavy icon sets, Monaco/Tiptap editors, Google Maps) must NOT execute during initial hydration.
- Attach initialization listeners to first user interaction (
pointerenter,scroll,touchstart) or wrap inrequestIdleCallback.
- Eliminate Barrel File Bloat:
- Avoid
import { Button } from '@/components'if it pulls 50 unused components into the bundle. - Use direct subpath imports or ensure build bundler supports Turbopack/Tree-shaking with
"sideEffects": false.
- Avoid
- Motion (motion.dev) & LazyMotion Architecture:
- In React animation projects, replace legacy heavyweight
framer-motionimports withmotion/react. - Wrap interactive trees in
<LazyMotion features={domAnimation} strict>and use lightweight<m.div>primitives, saving ~50KB+ gzip bundle size. - For vanilla JS animations or ultra-lightweight micro-interactions, use
motion/mini(~2.3KB native WAAPI engine).
- In React animation projects, replace legacy heavyweight
Pillar 6: Rendering Engine, Compositor & Animation Performance
content-visibility: auto:- Apply
content-visibility: autowithcontain-intrinsic-sizeto all below-the-fold content sections to allow the browser to skip rendering until scrolled into proximity:
- Apply
.section-below-fold {
content-visibility: auto;
contain-intrinsic-size: 0 600px;
}- Off-Main-Thread WAAPI Animations:
- Continuous ambient animations (marquees, background pulse, glow rings) and Motion transitions must run on the browser Compositor Thread using CSS
@keyframesor native Web Animations API (WAAPI) via Motion. - Never use JavaScript
requestAnimationFrameloops for static background decorations or layout properties (top,left,width,height). Animate exclusivelytransform(x,y,scale,rotate) andopacity.
- Continuous ambient animations (marquees, background pulse, glow rings) and Motion transitions must run on the browser Compositor Thread using CSS
- GPU Layer Promotion & DPR Capping:
- Promote animating elements with
transform: translateZ(0)orwill-change: transform. - On canvas/WebGL scenes with heavy backdrop filters, cap
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5))to protect mobile GPUs.
- Promote animating elements with
Pillar 7: Caching, Assets, Fonts & Network Hygiene
- Font Loading & Subsetting (Fontjoy Optimization):
- Use
next/font/googleor self-hosted WOFF2 withfont-display: swapand explicitsubsets: ['latin']. - Preload primary headline and body variable fonts; defer decorative display or code fonts.
- Use
- Immutable Asset Caching:
- Static assets (
/_next/static/*,/assets/*) with content hashes must have headers:Cache-Control: public, max-age=31536000, immutable.
- Static assets (
- Video Streaming Optimization:
- Video previews must set
preload="metadata"orpreload="none". Never usepreload="auto"across lists of cards or templates.
- Video previews must set
- Modern Image Formats:
- Generate AVIF and WebP variants with quality 75-80 (indistinguishable from original, 50-70% file size reduction).
3. The 5-Phase Agentic Performance Loop
When conducting performance optimization on any codebase or URL, follow this deterministic cycle:
[Phase 1: Measure] ──► [Phase 2: Diagnose] ──► [Phase 3: Surgical Fix] ──► [Phase 4: Benchmark] ──► [Phase 5: Document]
▲ │
└────────────────────────── If Scores < 100 ────────────────────────────────┘Phase 1: Baseline Measurement
- Synthetic Full Audit:
- Call
lighthouse-mcp(or runnpx lighthouse <URL> --output=json --preset=desktop/mobile) to capture standard scores across Performance, Accessibility, Best Practices, and SEO.
- Call
- Chromium Runtime Trace:
- Use
chrome-devtoolstoolperformance_start_traceto record real page load under 4x CPU Throttling and Slow 4G network. - Call
performance_analyze_insightwithinsightName: "LCPBreakdown"andinsightName: "DocumentLatency".
- Use
Phase 2: Root-Cause Diagnosis & Triage
- Classify bottlenecks by metric:
- LCP: Check hero image discovery, preload priority, CSS blocking time.
- INP/TBT: Identify Long Tasks in flame chart (>50ms); locate synchronous JS execution.
- CLS: Inspect layout shift clusters in trace; check missing dimensions or web font swapping.
- Bundle: Inspect network waterfall and bundle analyzer output (
@next/bundle-analyzer/source-map-explorer).
Phase 3: Surgical Implementation
- Apply targeted fixes from the 7 Pillars without deleting user features or compromising architecture.
- Follow strict Single Source of Truth (SSOT) and zero-workaround protocol.
Phase 4: Benchmarking & Iteration
- Re-run
lighthouse-mcpaudit andchrome-devtoolstrace. - Compare before/after metrics against targets (LCP ≤ 1.2s, INP ≤ 50ms, CLS = 0.000).
- If performance score < 100, repeat Phase 2 with specific remaining issues.
Phase 5: Documentation & Memory Persistence
- Record final metrics in project
MEMORY.mdor audit log. - Persist key architectural decisions and performance baselines to MemPalace via
mempalace_diary_write.
4. MCP Tools Reference Matrix for Performance
| Task | Primary Tool | Secondary Tool / CLI |
| Synthetic Audit & Scores | lighthouse-mcp (@danielsogl/lighthouse-mcp) | npx unlighthouse --site <url> |
| Deep CPU Trace & Long Tasks | chrome-devtools (performance_start_trace) | Chrome DevTools Flamechart |
| LCP Breakdown Analysis | chrome-devtools (performance_analyze_insight) | PerformanceObserver API |
| Memory Leaks & Heap Size | chrome-devtools (take_heapsnapshot) | Heap Profiler |
| Network Waterfall & Payload | chrome-devtools (list_network_requests) | HAR analysis |
| E2E Multi-step User Interaction | puppeteer (puppeteer_navigate, puppeteer_click) | Playwright trace |
| Architecture & Knowledge Recall | mempalace (mempalace_search, mempalace_kg_query) | Local MEMORY.md |
5. Verification & QA Checklist
Before concluding any web performance task:
- Lighthouse Mobile Score: Performance ≥ 95 (Desktop: 100).
- LCP: Hero element renders in < 1.2s with
fetchpriority="high"and AVIF/WebP. - INP: Zero tasks exceeding 50ms on main thread; UI interactions feel instantaneous.
- CLS: Score is 0.000; all media has explicit dimensions and fonts use zero-shift fallbacks.
- Bundle Size: JS bundle meets budget (< 150KB gzip for critical path).
- Compositor: Continuous animations execute on compositor thread (WAAPI/CSS).
- Lazy Hydration: Heavy 3D/Canvas/widgets gated behind user interaction.
- TypeScript Check:
npx tsc --noEmitpasses without errors.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

