skill · from the nextjs-expert plugin
/optimize
Analyze and optimize Next.js application performance
- nextjs-expert plugin
- Slash command
you ›install the nextjs-expert plugin
metaphor ›Installed nextjs-expert. /optimize is ready.
you ›/optimize
metaphor ›Loaded the optimize skill. What should I work on?
What the agent is told
This is the skill's SKILL.md, exactly what Metaphor reads before the task.
You are analyzing a Next.js application to identify and recommend performance optimizations.
Workflow
Step 1: Analyze Current State
Examine the codebase for common performance issues:
Component Boundaries
- Find
'use client'directives - Check if client boundaries are too high
- Look for unnecessary client components
- Find
Data Fetching
- Check for waterfalls (sequential fetches)
- Look for missing parallel fetching
- Identify uncached requests
Bundle Size
- Check for large client-side imports
- Look for unused dependencies
- Find components that could be server-rendered
Image Optimization
- Look for
<img>tags (should usenext/image) - Check for missing width/height
- Identify unoptimized images
- Look for
Caching
- Check fetch() cache options
- Look for missing revalidation strategies
- Identify static vs dynamic content
Step 2: Apply Skills
Use relevant skills to understand best practices:
server-components- For component boundary optimizationapp-router- For routing and layout optimizationroute-handlers- For API optimizationserver-actions- For mutation optimization
Step 3: Generate Report
Create an optimization report covering:
Optimization Categories
1. Server/Client Component Boundaries
Check for:
- Client components that don't use hooks or browser APIs
- Large component trees under 'use client'
- Data fetching in client components
Recommendations:
- Move data fetching to server components
- Push 'use client' boundaries down
- Pass server data as props to client components
2. Data Fetching Patterns
Check for:
- Sequential await statements
- fetch() without cache options
- Missing generateStaticParams
Recommendations:
// Before: Sequential
const user = await getUser()
const posts = await getPosts()
// After: Parallel
const [user, posts] = await Promise.all([
getUser(),
getPosts(),
])
3. Bundle Optimization
Check for:
- Large npm packages in client components
- Missing dynamic imports
- Unused exports
Recommendations:
// Dynamic import for client-only libraries
const Chart = dynamic(() => import('./Chart'), {
loading: () => <ChartSkeleton />,
ssr: false,
})
4. Image Optimization
Check for:
<img>instead of<Image>- Missing blur placeholders
- Unoptimized formats
Recommendations:
import Image from 'next/image'
<Image
src="/hero.jpg"
alt="Hero"
width={1200}
height={600}
priority // For above-the-fold images
placeholder="blur"
/>
5. Caching Strategy
Check for:
- Missing cache directives
- No revalidation configuration
- Overly dynamic pages
Recommendations:
// Cache with revalidation
const data = await fetch(url, {
next: { revalidate: 3600 }, // 1 hour
})
// Tag-based revalidation
const data = await fetch(url, {
next: { tags: ['products'] },
})
6. Loading States
Check for:
- Missing loading.tsx files
- No Suspense boundaries
- Blocking renders
Recommendations:
- Add loading.tsx for route segments
- Wrap slow components in Suspense
- Use streaming for large pages
Output Format
After analysis, provide:
- Summary: Overall performance assessment
- High Priority: Issues with biggest impact
- Quick Wins: Easy fixes with good returns
- Code Changes: Specific file changes needed
- Metrics: Expected improvements
Example Report
## Performance Analysis Report
### Summary
Found 5 high-priority and 8 medium-priority optimization opportunities.
### High Priority Issues
1. **Large Client Boundary** (app/dashboard/page.tsx)
- Impact: High
- Issue: Entire dashboard is client-rendered
- Fix: Split into server/client components
2. **Sequential Data Fetching** (app/products/page.tsx)
- Impact: High
- Issue: 3 sequential await calls
- Fix: Use Promise.all()
### Quick Wins
1. Add loading.tsx to /dashboard
2. Convert 12 <img> tags to <Image>
3. Add cache options to 8 fetch() calls
### Estimated Impact
- Bundle size: -15%
- TTFB: -200ms
- LCP: -500ms
Questions
What is the optimize skill?
Analyze and optimize Next.js application performance
How do I use optimize in Metaphor?
Install the nextjs-expert plugin by asking the agent "install the nextjs-expert plugin", then type /optimize in the composer.
What is a skill?
A skill is a set of written instructions the agent reads before it starts a kind of task. It changes how the agent works, not what it is allowed to do.
More from nextjs-expert
- /add-authSkillAdd authentication to a Next.js applicationin nextjs-expert
- /app-routerSkillThis skill should be used when the user asks to "create a Next.js route", "add a page", "set up layouts", "implement loading states", "add error boundaries"…in nextjs-expert
- /auth-patternsSkillThis skill should be used when the user asks about "authentication in Next.js", "NextAuth", "Auth.js", "middleware auth", "protected routes", "session…in nextjs-expert
- /route-handlersSkillThis skill should be used when the user asks to "create an API route", "add an endpoint", "build a REST API", "handle POST requests", "create route handlers"…in nextjs-expert
- /scaffoldSkillScaffold Next.js components following best practicesin nextjs-expert
- /server-actionsSkillThis skill should be used when the user asks about "Server Actions", "form handling in Next.js", "mutations", "useFormState", "useFormStatus"…in nextjs-expert