Communitygithub.com

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

skills 是什么?

skills is a Claude Code agent skill that upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/image-optimization

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Image Optimization

Rules

  • Use next/image for all images in Next.js — automatic optimization, lazy loading, responsive srcsets
  • Always set width and height or use fill with a sized container — prevents layout shift (CLS)
  • Blur placeholder: generate blurDataURL at build/upload time with plaiceholder or use placeholder="blur" for static imports
  • Remote images: configure remotePatterns in next.config.js — whitelist CDN domains
  • Upload flow: client → presigned URL (S3/R2/Supabase Storage) → direct upload → store URL in database
  • Resize on upload: use sharp server-side to create multiple sizes (thumbnail, medium, full) — don't serve originals
  • Formats: serve WebP/AVIF via next/image auto-format — fallback to JPEG for compatibility
  • CDN delivery: store originals in object storage (S3, R2), serve through CDN (CloudFront, Cloudflare) with cache headers
  • Max file size validation: check on client (before upload) and server (before processing) — 5-10MB typical limit

Patterns

// next/image with blur placeholder
import Image from "next/image";

<Image
  src="/hero.jpg"
  alt="Hero image"
  width={1200}
  height={630}
  placeholder="blur"
  blurDataURL="data:image/jpeg;base64,/9j/4AAQ..."
  priority // above the fold
/>

// Fill mode for dynamic containers
<div className="relative aspect-video">
  <Image src={url} alt={alt} fill className="object-cover" sizes="(max-width: 768px) 100vw, 50vw" />
</div>
// Server-side resize with 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 };
}

Avoid

  • Using <img> tags in Next.js — lose automatic optimization, lazy loading, and format conversion
  • Missing sizes prop on responsive images — browser can't pick the right srcset size
  • Serving unresized originals — a 5MB photo displayed at 400px is wasteful
  • Skipping file type validation — check MIME type server-side, not just file extension

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

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

YepAPI/skills

Tool-use patterns, multi-step reasoning, agent orchestration, and structured outputs.

YepAPI/skills

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

YepAPI/skills

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

YepAPI/skills

Web analytics integration — event tracking, custom dashboards, privacy-first.

YepAPI/skills

Framer Motion — transitions, scroll animations, layout animations.

YepAPI/skills

OpenAPI 3.1 from Zod schemas, interactive docs with Swagger/Scalar, versioning, and example requests for every endpoint.

YepAPI/skills

Authentication security — bcrypt/argon2 hashing, brute force protection, secure password resets.

YepAPI/skills

Session auth, social providers, CSRF protection, and secure cookie patterns.

YepAPI/skills

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

YepAPI/skills

Link building research and backlink audit using YepAPI.

YepAPI/skills

MDX blog setup, RSS feed generation, sitemap.xml, structured data/JSON-LD, and related posts.

YepAPI/skills

Redis caching, CDN cache headers, stale-while-revalidate, cache invalidation, React Query.

YepAPI/skills

Recharts/Chart.js data visualization — bar, line, area, pie charts.

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

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

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

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

相关技能