ワンクリックで
performance-optimization
Guide for optimizing web performance and Core Web Vitals. Use when analyzing or improving page performance.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Guide for optimizing web performance and Core Web Vitals. Use when analyzing or improving page performance.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | performance-optimization |
| description | Guide for optimizing web performance and Core Web Vitals. Use when analyzing or improving page performance. |
Follow this guide to optimize web performance and Core Web Vitals:
Largest Contentful Paint (LCP): < 2.5s First Input Delay (FID): < 100ms Cumulative Layout Shift (CLS): < 0.1
// Lazy load routes
import { lazy, Suspense } from 'react';
const Dashboard = lazy(() => import('./pages/Dashboard'));
const Settings = lazy(() => import('./pages/Settings'));
function App() {
return (
<Suspense fallback={<LoadingSpinner />}>
<Routes>
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/settings" element={<Settings />} />
</Routes>
</Suspense>
);
}
// Lazy load heavy components
const Chart = lazy(() => import('./components/Chart'));
<!-- Modern formats with fallback -->
<picture>
<source srcset="image.avif" type="image/avif" />
<source srcset="image.webp" type="image/webp" />
<img src="image.jpg" alt="Description" loading="lazy" />
</picture>
<!-- Responsive images -->
<img
src="small.jpg"
srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px"
alt="Description"
loading="lazy"
/>
import Image from 'next/image';
<Image
src="/hero.jpg"
alt="Hero image"
width={1200}
height={600}
priority // For LCP image
placeholder="blur"
/>
// Vite: Analyze bundle
import { visualizer } from 'rollup-plugin-visualizer';
export default {
plugins: [
visualizer({
open: true,
gzipSize: true,
}),
],
};
// Tree shaking: Import only what you need
// ❌ Bad
import _ from 'lodash';
// ✅ Good
import debounce from 'lodash/debounce';
// Expensive calculation
const sortedData = useMemo(() => {
return data.sort((a, b) => a.value - b.value);
}, [data]);
// Prevent re-renders
const MemoizedComponent = memo(function ExpensiveComponent({ data }) {
// Complex rendering
});
// Stable callbacks
const handleClick = useCallback(() => {
doSomething(id);
}, [id]);
import { useVirtualizer } from '@tanstack/react-virtual';
function VirtualList({ items }) {
const parentRef = useRef();
const virtualizer = useVirtualizer({
count: items.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 50,
});
return (
<div ref={parentRef} style={{ height: '400px', overflow: 'auto' }}>
<div style={{ height: virtualizer.getTotalSize() }}>
{virtualizer.getVirtualItems().map(item => (
<div key={item.key} style={{ transform: `translateY(${item.start}px)` }}>
{items[item.index]}
</div>
))}
</div>
</div>
);
}
// Express.js
app.use(express.static('public', {
maxAge: '1y', // Cache static assets for 1 year
immutable: true,
}));
// Cache-Control headers
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
// workbox-config.js
module.exports = {
globDirectory: 'dist/',
globPatterns: ['**/*.{html,js,css,png,jpg,svg}'],
swDest: 'dist/sw.js',
runtimeCaching: [{
urlPattern: /^https:\/\/api\.example\.com/,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
expiration: {
maxEntries: 50,
maxAgeSeconds: 300,
},
},
}],
};
<!-- Preload critical fonts -->
<link
rel="preload"
href="/fonts/Inter-Regular.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<!-- Use font-display: swap -->
<style>
@font-face {
font-family: 'Inter';
src: url('/fonts/Inter-Regular.woff2') format('woff2');
font-display: swap; /* Prevents invisible text */
font-weight: 400;
}
</style>
<!-- Preconnect to third-party origins -->
<link rel="preconnect" href="https://api.example.com" />
<link rel="dns-prefetch" href="https://analytics.example.com" />
<!-- Prefetch next page -->
<link rel="prefetch" href="/dashboard" />
<!-- Preload critical resources -->
<link rel="preload" href="/critical.css" as="style" />
<link rel="preload" href="/hero.jpg" as="image" />
// Debounce: Wait for silence
const debouncedSearch = useMemo(
() => debounce((query: string) => {
performSearch(query);
}, 300),
[]
);
// Throttle: Limit frequency
const throttledScroll = useMemo(
() => throttle(() => {
handleScroll();
}, 100),
[]
);
// ❌ N+1 Query Problem
const posts = await prisma.post.findMany();
for (const post of posts) {
const author = await prisma.user.findUnique({
where: { id: post.authorId }
});
}
// ✅ Single query with include
const posts = await prisma.post.findMany({
include: { author: true },
});
// ✅ Add indexes for frequent queries
model Post {
id String @id
authorId String
createdAt DateTime
@@index([authorId])
@@index([createdAt])
}
// Enable gzip/brotli compression
import compression from 'compression';
app.use(compression({
level: 6, // Compression level
threshold: 1024, // Only compress if > 1KB
}));
Run Lighthouse and fix issues:
# Chrome DevTools: Lighthouse tab
# Or CLI:
npx lighthouse https://example.com --view
Common fixes:
// Web Vitals
import { getCLS, getFID, getLCP } from 'web-vitals';
getCLS(console.log);
getFID(console.log);
getLCP(console.log);
// Performance API
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
console.log(entry.name, entry.startTime);
}
});
observer.observe({ entryTypes: ['navigation', 'resource'] });
Checklist for auditing and fixing accessibility issues (WCAG 2.1 AA compliance). Use when reviewing components or pages for accessibility.
Guide for creating RESTful API endpoints with validation and error handling. Use when implementing backend API routes.
Guide for implementing secure authentication with JWT and session management. Use when adding authentication to an application.
Guide for creating responsive layouts with CSS. Use when implementing responsive design or fixing layout issues.
Guide for designing database schemas with Prisma ORM. Use when creating or modifying database models.
Guide for consistent error handling across frontend and backend. Use when implementing error handling logic.