Back to ⚡ Performance & Optimization

Optimize Images for Web

PerformanceImagesOptimizationNext.js
---
description: Compress and serve images in modern formats for faster loading
---

1. **Use Next.js Image Component**:
- Automatic optimization and lazy loading.
import Image from 'next/image';

<Image
src="/hero.jpg"
alt="Hero"
width={1200}
height={600}
priority // for above-the-fold images
placeholder="blur" // optional: shows blur while loading
/>


2. **Configure Remote Patterns (Next.js 14+)**:
- domains is deprecated. Use remotePatterns for better security.
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.example.com',
pathname: '/images/**',
},
],
formats: ['image/webp', 'image/avif'],
},
};


3. **Modern Formats (AVIF)**:
- Enable AVIF for smaller file sizes (20% smaller than WebP).
- Next.js automatically handles format negotiation.

4. **Pro Tips**:
- Always specify width/height to prevent CLS.
- Use fill + object-fit for responsive containers.
- Use sizes prop for responsive images: sizes="(max-width: 768px) 100vw, 50vw".
By Antigravity Team

How to Use This Workflow

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/workflows/
  3. Save the file as optimize-images-nextjs-image-component-webp.md
  4. In Antigravity, type /optimize_images_nextjs_image_component_webp or just describe what you want to do

Learn more about workflows →

Related Workflows

Recommended Rules

View more rules →

Recommended MCP Servers

View more MCP servers →

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide