Next.js performance optimizations including next/image, next/font, dynamic imports, caching strategies, and bundle optimization. Use when optimizing Next.js apps for speed or Core Web Vitals.
Optimize Next.js apps for Core Web Vitals using next/image, next/font, dynamic imports, and strategic caching. Use when you need to fix CLS, reduce bundle size, or improve LCP.
/plugin marketplace add jovermier/cc-stack-marketplace/plugin install cc-nextjs@cc-stack-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Expert guidance for optimizing Next.js applications.
| Concern | Solution | Impact |
|---|---|---|
| Images | next/image with sizing | CLS prevention, auto-optimization |
| Fonts | next/font | No layout shift, self-hosted |
| Heavy components | next/dynamic | Reduced initial bundle |
| Data caching | fetch options (revalidate) | Reduced server load |
| Client navigation | Link component | Instant transitions |
| Bundle size | Tree shaking, no unused deps | Faster JS loading |
Specify a number or describe your performance concern.
| Response | Reference to Read |
|---|---|
| 1, "image", "img", "optimization", "cls" | images.md |
| 2, "font", "layout shift", "typography" | fonts.md |
| 3, "dynamic", "import", "lazy", "split" | code-splitting.md |
| 4, "cache", "revalidate", "isr", "fetch" | caching.md |
| 5, "navigation", "link", "prefetch" | navigation.md |
Optimize images: Use next/image with width/height for all images. Prevents CLS and enables automatic optimization.
Self-host fonts: Use next/font to eliminate requests to external font services and prevent layout shift.
Dynamic import heavy code: Use next/dynamic for components that are heavy or not immediately visible.
Client-side navigation: Use Link component for all internal links. Enables instant page transitions.
Cache strategically: Use appropriate fetch caching (force-cache, no-store, revalidate) based on data freshness needs.
| Issue | Severity | Impact | Fix |
|---|---|---|---|
Using <img> instead of next/image | High | CLS, no optimization | Use next/image |
| External fonts | Medium | Layout shift, extra request | Use next/font |
| Large initial bundle | High | Slow initial load | Dynamic imports |
| No caching on static data | Medium | Unnecessary server load | Add revalidate |
Using <a> instead of Link | High | Full page reload | Use Link |
| No priority hints | Low | Delayed LCP | Use priority prop |
// Good: next/image with sizing
import Image from 'next/image'
<Image
src="/avatar.jpg"
width={100}
height={100}
alt="Avatar"
priority // For above-fold images
/>
// Good: next/font
import { Inter } from 'next/font/google'
const inter = Inter({ subsets: ['latin'] })
export default function RootLayout({ children }: { children: ReactNode }) {
return <html className={inter.className}>{children}</html>
}
// Good: Dynamic import for heavy component
import dynamic from 'next/dynamic'
const HeavyChart = dynamic(() => import('./HeavyChart'), {
loading: () => <div>Loading...</div>,
ssr: false, // If client-only
})
// Good: Appropriate caching
export const revalidate = 3600 // Revalidate every hour
async function getData() {
const res = await fetch('https://api.example.com/data', {
next: { revalidate: 3600 } // or { revalidate: 0 } for no cache
})
return res.json()
}
| File | Topics |
|---|---|
| images.md | next/image, sizing, priority, formats |
| fonts.md | next/font, Google fonts, local fonts |
| code-splitting.md | Dynamic imports, route splitting |
| caching.md | fetch options, ISR, revalidatePath |
| navigation.md | Link component, prefetching, scroll |
Performance is good when:
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.