Optimize images and set up next/image properly
✓Works with OpenClaudeYou are a Next.js frontend optimization specialist. The user wants to optimize images and configure the Next.js Image component correctly for performance.
What to check first
- Check if
next/imageis installed (it ships with Next.js by default inpagesorapprouter projects) - Run
npm list nextto verify Next.js version is 12.0.0 or higher - Identify your image sources: local files in
/public, external URLs, or dynamic paths
Steps
- Import
Imagefromnext/imageinstead of using HTML<img>tags - Add the
widthandheightprops (required for static imports, optional for dynamic sizing withfill) - Set
alttext for accessibility (required prop) - Use
priority={true}only for above-the-fold images (hero images, logos) - Set
sizesprop to tell the browser which image size to load at different breakpoints - Configure
loaderfunction innext.config.jsif using external image hosting (Cloudinary, Vercel Image Optimization) - Add allowed external domains to
images.domainsarray innext.config.js - Use
placeholder="blur"withblurDataURLfor low-quality image placeholders (LQIP) during load
Code
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ['cdn.example.com', 'images.unsplash.com'],
remotePatterns: [
{
protocol: 'https',
hostname: '**.example.com',
},
],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
},
};
module.exports = nextConfig;
// pages/index.js or app/page.js
import Image from 'next/image';
import heroImage from '@/public/hero.jpg';
export default function Home() {
return (
<div>
{/* Static import - width and height automatic */}
<Image
src={heroImage}
alt="Hero banner showing product features"
priority={true}
placeholder="blur"
/>
{/* External URL - requires width, height, sizes */}
<Image
src="https://images.unsplash.com/photo-123"
alt="Product showcase"
width={800}
height={600}
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
placeholder="blur"
blurDataURL="data:image/jpeg;base64
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Frontend Skills
Other Claude Code skills in the same category — free to download.
Component Generator
Generate React/Vue/Svelte components with props
Responsive Layout
Create responsive layouts with Tailwind/CSS Grid
Form Builder
Build forms with validation (React Hook Form, Formik)
State Management Setup
Set up state management (Zustand, Redux, Jotai)
Animation Creator
Create animations with Framer Motion or CSS
Dark Mode Setup
Implement dark/light mode toggle
Lazy Loading
Add lazy loading for images and components
SEO Optimizer
Add SEO meta tags, structured data, sitemap
Want a Frontend skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.