Agent skill
performance-patterns
Web performance patterns - Core Web Vitals, code splitting, caching, and bundle optimization. Use when improving web application performance.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/performance-patterns
SKILL.md
Web Performance Patterns
Core Web Vitals Targets
| Metric | Target | What It Measures |
|---|---|---|
| LCP (Largest Contentful Paint) | < 2.5s | Loading performance |
| INP (Interaction to Next Paint) | < 200ms | Responsiveness |
| CLS (Cumulative Layout Shift) | < 0.1 | Visual stability |
Lighter Alternatives
| Heavy | Light Alternative |
|---|---|
| moment.js (300KB) | date-fns (~5KB/fn), dayjs (2KB) |
| lodash (70KB) | Individual imports, native methods |
| axios (13KB) | fetch API (native) |
// ❌ Imports entire library
import _ from 'lodash';
// ✅ Import only what you need
import debounce from 'lodash/debounce';
Code Splitting
// Route-based splitting
import { lazy, Suspense } from 'react';
const Dashboard = lazy(() => import('./pages/Dashboard'));
function App() {
return (
<Suspense fallback={<PageLoader />}>
<Routes>
<Route path="/dashboard" element={<Dashboard />} />
</Routes>
</Suspense>
);
}
// Next.js dynamic imports
import dynamic from 'next/dynamic';
const HeavyChart = dynamic(() => import('@/components/HeavyChart'), {
loading: () => <ChartSkeleton />,
ssr: false,
});
Dynamic Library Import
// Load heavy libraries only when needed
async function generatePDF(data) {
const { jsPDF } = await import('jspdf');
const doc = new jsPDF();
return doc;
}
Layout Stability (CLS)
// Reserve space for images
<div style={{ aspectRatio: '16/9' }}>
<Image src={src} alt={alt} fill />
</div>
// Reserve space for dynamic content
<div style={{ minHeight: '250px' }}>
<Suspense fallback={<Skeleton height={250} />}>
<DynamicContent />
</Suspense>
</div>
/* Font loading without CLS */
@font-face {
font-family: 'CustomFont';
src: url('/fonts/custom.woff2') format('woff2');
font-display: swap;
}
Caching with TanStack Query
function useProducts() {
return useQuery({
queryKey: ['products'],
queryFn: fetchProducts,
staleTime: 5 * 60 * 1000, // Fresh for 5 minutes
gcTime: 30 * 60 * 1000, // Keep in cache 30 minutes
});
}
// Prefetch on hover
const queryClient = useQueryClient();
const handleMouseEnter = () => {
queryClient.prefetchQuery({
queryKey: ['product', productId],
queryFn: () => fetchProduct(productId),
});
};
Debounce Hook
import { useMemo } from 'react';
import debounce from 'lodash/debounce';
function SearchInput() {
const debouncedSearch = useMemo(
() => debounce((term: string) => {
performSearch(term);
}, 300),
[]
);
return (
<input
onChange={(e) => debouncedSearch(e.target.value)}
placeholder="Search..."
/>
);
}
Virtualization (Long Lists)
import { FixedSizeList } from 'react-window';
<FixedSizeList
height={400}
itemCount={items.length}
itemSize={35}
width="100%"
>
{({ index, style }) => (
<div style={style}>{items[index].name}</div>
)}
</FixedSizeList>
Checklist
- Code split by route
- Lazy load below-fold content
- Use modern image formats (WebP/AVIF)
- Set image dimensions (prevent CLS)
- Replace heavy libraries with lighter alternatives
- Enable caching (TanStack Query staleTime)
- Debounce expensive operations
- Virtualize long lists
- Measure Core Web Vitals
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?