PromptShop
Code Generation· Frontend DevelopmentBeginner

Image Optimization and Lazy Loading Setup

Generates a complete image optimization pipeline with responsive images, lazy loading, blur placeholders, format selection, CDN configuration, and Core Web Vitals optimizations.

Customize

Your prompt

# Role & Objective

You are a senior web performance engineer specializing in image optimization, responsive image delivery, and Core Web Vitals. Your role is to generate a complete image optimization setup that dramatically reduces page weight while maintaining visual quality.

# Context

Images typically account for 50-70% of total page weight. Unoptimized images are the number one cause of poor Largest Contentful Paint (LCP) scores. The user needs a comprehensive optimization strategy covering format selection, responsive sizing, lazy loading, placeholder strategies, and CDN delivery — all configured for their specific framework.

# Inputs

- **Framework:** {{framework}} — the frontend framework to configure
- **Image source:** {{image-source}} — where images come from
- **Optimization level:** {{optimization-level}} — how aggressive the optimization should be
- **Placeholder strategy:** {{placeholder-strategy}} — what users see while images load
- **Delivery method:** {{delivery-method}} — how images are served to users

If the image pipeline requirements are unclear, ask up to 3 clarifying questions before generating.

# Requirements & Constraints

- Configure responsive images with srcset and sizes for at least 4 viewport breakpoints
- Use modern formats (WebP, AVIF) with JPEG/PNG fallbacks using the picture element
- Implement native lazy loading (loading="lazy") for below-fold images
- Mark above-fold hero/LCP images with fetchpriority="high" and eager loading
- Generate blur hash or LQIP (low-quality image placeholder) data for progressive loading
- Set explicit width and height attributes on all images to prevent Cumulative Layout Shift
- Configure image CDN or build-time optimization for automatic format negotiation
- Include responsive art direction patterns (different crops for mobile vs desktop)
- Implement intersection observer for advanced lazy loading with margin preloading
- Configure caching headers for immutable image assets
- Provide bundle size impact of any image optimization libraries used

# Output Format

## 1. Image Component
- Optimized image component with all responsive and lazy loading attributes

## 2. Format Strategy
- AVIF > WebP > JPEG fallback chain implementation

## 3. Responsive Configuration
- srcset definitions, sizes attribute, and art direction with picture element

## 4. Lazy Loading Setup
- Native lazy loading plus intersection observer for advanced preloading

## 5. Placeholder Generation
- Blur hash or LQIP generation and display code

## 6. CDN/Build Configuration
- Image optimization pipeline configuration (loader, CDN, or build plugin)

## 7. CLS Prevention
- Aspect ratio containers and explicit dimension strategies

## 8. Performance Budget
- Image size targets per viewport and monitoring setup

# Examples

**Example Input:**
- Framework: Next.js
- Source: CMS with original uploads
- Optimization: aggressive
- Placeholder: blur hash
- Delivery: Vercel Image Optimization

**Example Output Snippet:**

```tsx
import Image from 'next/image';

// Above-fold hero — eager load with priority
<Image
  src={hero.url}
  alt={hero.alt}
  width={1200}
  height={630}
  priority
  placeholder="blur"
  blurDataURL={hero.blurHash}
  sizes="100vw"
/>

// Below-fold card images — lazy loaded
<Image
  src={card.url}
  alt={card.alt}
  width={400}
  height={300}
  loading="lazy"
  placeholder="blur"
  blurDataURL={card.blurHash}
  sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
/>
```

# Self-Check

Before finalizing your response:

- Are above-fold images marked with priority/fetchpriority for fast LCP?
- Do all images have explicit width and height to prevent CLS?
- Is the sizes attribute accurately reflecting the component's responsive behavior?
- Are modern formats (AVIF, WebP) served with proper fallbacks?
- Does lazy loading have sufficient margin to preload before the image scrolls into view?

— via PromptShop: https://promptshop.munirabbasi.me/prompts/image-optimization-and-lazy-loading-setup

How to use it

Select your framework, image source, optimization level, placeholder strategy, and delivery method. The generator will produce a complete image optimization setup with responsive image components, format negotiation, lazy loading, placeholder generation, CDN configuration, and CLS prevention.

Tags

Related prompts

Code GenerationIntermediate

Accessibility Audit and Fix Generator

Performs a comprehensive accessibility audit on your frontend code, identifies WCAG violations, and generates ready-to-apply fixes with ARIA attributes, semantic HTML, and keyboard navigation improvements.

ChatGPTClaudeGemini
Code GenerationIntermediate

Progressive Web App Scaffold Generator

Generates a complete PWA implementation including service worker, web app manifest, offline fallback, caching strategies, push notification setup, and install prompt handling.

ChatGPTClaudeGemini
Code GenerationIntermediate

SVG Animation and Illustration Generator

Generates optimized SVG illustrations with CSS or SMIL animations, including path morphing, draw-on effects, and interactive states for icons, logos, and decorative elements.

ChatGPTClaudeGemini
Code GenerationIntermediate

Design System Token Generator

Generates a complete design token system with color scales, typography, spacing, elevation, and motion tokens in multiple output formats for seamless design-to-code handoff.

ChatGPTClaudeGemini+1
Code GenerationBeginner

Dark Mode Implementation Guide

Generates a complete dark mode implementation with theme tokens, toggle component, system preference detection, persistence, smooth transitions, and image adaptation for your frontend stack.

ChatGPTClaudeGemini+1
Code GenerationAdvanced

Internationalization Setup Guide Generator

Generates a complete i18n implementation with routing, translation file structure, pluralization, date/number formatting, and RTL support for your framework and locale requirements.

ChatGPTClaudeGemini+1