Communitygithub.com

YepAPI 画像最適化スキル

アップロード処理、リサイズ・圧縮、CDN配信、ぼかしプレースホルダー、next/image パターンを実現します。

YepAPI 画像最適化スキル とは?

このスキルは、Next.js プロジェクトにおける画像最適化のための包括的なベストプラクティスとコードパターンを提供します。`next/image` コンポーネントを常に使用し、自動最適化、遅延読み込み、レスポンシブ srcset を活用します。ぼかしプレースホルダー(`blurDataURL`)の生成や、`sharp` によるサーバーサイドでのリサイズ(サムネイル・中・大フォーマット)を推奨し、元画像をそのまま配信しないことで帯域を節約します。また、S3/R2/Supabase Storage へのアップロードフロー、CDN(CloudFront/Cloudflare)経由の配信、ファイルサイズバリデーション、WebP/AVIF 形式の自動変換などもカバーします。主に Next.js プロジェクト向けですが、アップロード処理全般にも応用可能で、`remotePatterns` 設定によるリモート画像ドメインのホワイトリスト登録も含まれます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/image-optimization

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

画像最適化

ルール

  • Next.js ではすべての画像に next/image を使用 — 自動最適化、遅延読み込み、レスポンシブ srcset を実現
  • 常に width と height を設定するか、fill をサイズ指定コンテナと併用 — レイアウトシフト (CLS) を防止
  • ぼかしプレースホルダー: ビルド時またはアップロード時に plaiceholder で blurDataURL を生成、静的インポートでは placeholder="blur" を使用
  • リモート画像: next.config.js で remotePatterns を設定 — CDN ドメインをホワイトリストに追加
  • アップロードフロー: クライアント → 署名付き URL (S3/R2/Supabase Storage) → 直接アップロード → URL をデータベースに保存
  • アップロード時にリサイズ: sharp をサーバーサイドで使用して複数のサイズ(サムネイル、中、大)を生成 — 元画像は配信しない
  • フォーマット: next/image の自動フォーマットで WebP/AVIF を提供 — 互換性のために JPEG にフォールバック
  • CDN 配信: 元画像をオブジェクトストレージ (S3、R2) に保存し、CDN (CloudFront、Cloudflare) を通じてキャッシュヘッダー付きで配信
  • 最大ファイルサイズバリデーション: クライアント側(アップロード前)とサーバー側(処理前)で確認 — 通常 5〜10MB が上限

パターン

// ぼかしプレースホルダー付き next/image
import Image from "next/image";

<Image
  src="/hero.jpg"
  alt="ヒーロー画像"
  width={1200}
  height={630}
  placeholder="blur"
  blurDataURL="data:image/jpeg;base64,/9j/4AAQ..."
  priority // ファーストビュー
/>

// 動的なコンテナ向け Fill モード
<div className="relative aspect-video">
  <Image src={url} alt={alt} fill className="object-cover" sizes="(max-width: 768px) 100vw, 50vw" />
</div>
// sharp によるサーバーサイドリサイズ
import sharp from "sharp";

async function processUpload(buffer: Buffer) {
  const thumbnail = await sharp(buffer).resize(200, 200, { fit: "cover" }).webp({ quality: 80 }).toBuffer();
  const medium = await sharp(buffer).resize(800).webp({ quality: 85 }).toBuffer();
  const full = await sharp(buffer).resize(1920).webp({ quality: 90 }).toBuffer();
  return { thumbnail, medium, full };
}

避けるべきこと

  • Next.js で <img> タグを使用 — 自動最適化、遅延読み込み、フォーマット変換が失われる
  • レスポンシブ画像で sizes プロパティを省略 — ブラウザが適切な srcset サイズを選択できない
  • リサイズしていない元画像を配信 — 400px で表示するのに 5MB の写真は無駄が多い
  • ファイルタイプバリデーションをスキップ — ファイル拡張子だけでなくサーバーサイドで MIME タイプを確認

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Tenant isolation (row-level vs schema), subdomain routing, per-tenant config, and data partitioning.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

関連スキル