Communitygithub.com

ComeOnOliver/skillshub

Next.js 图片、字体、脚本和元数据优化策略。在优化 Next.js 图片、字体、脚本或页面元数据性能时使用。

skillshub 是什么?

此技能提供了 Next.js 应用程序的核心优化方法和最佳实践,重点针对图片、字体、脚本和元数据进行性能调优。它强调“先监控,后优化”的理念,通过 LCP、CLS、INP 等核心 Web 指标来识别瓶颈。该技能详细介绍了使用 `next/image` 防止布局偏移,利用 `next/font` 实现零布局偏移并本地托管字体,通过 `next/script` 控制第三方脚本加载策略,以及使用静态 `metadata` 或 `generateMetadata` 改善 SEO。此外,还涵盖动态导入、`@next/bundle-analyzer` 分析包大小以及 Next.js 15+ 的部分预渲染等功能。技能同时明确列出了常见反模式,如避免使用原生 `<img>` 标签或 Google Fonts CDN 链接。支持所有 Next.js 项目,适用于使用 Next.js 的应用开发场景。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/HoangNguyen0403/agent-skills-standard/nextjs-optimization

在你喜欢的 AI 中提问

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

文档

优化

优先级:P1(高)

Next.js 提供的核心优化原语。先监控,后优化。

监控(核心 Web 指标)

在进行优化之前,使用以下方法识别瓶颈:

  • LCP(最大内容绘制):初始加载速度。目标 < 2.5 秒。
  • CLS(累积布局偏移):视觉稳定性。目标 < 0.1。
  • INP(与下一次交互的延迟):响应速度。目标 < 200 毫秒。
  • 工具:Chrome DevTools "Performance" 标签页、next/speed-insights 或 React Profiler。

实现指南

  • 图片:始终使用 next/image 以防止 CLS(累积布局偏移)。为首屏图片设置 priority 以改善 LCP(最大内容绘制)。使用 sizes(例如 (max-width: 768px) 100vw, 33vw)和 placeholder="blur" 以获得更好的用户体验。

  • 字体:使用 next/font(Google 或本地)以优化实现 零布局偏移。这会自动在本地托管字体并添加 font-display: swap。

  • 脚本:使用 next/script 并采用适当的策略:beforeInteractive(关键)、afterInteractive(默认/分析)或 lazyOnload(低优先级/社交小部件/聊天)。

  • 元数据:定义 static metadata 或对动态路由使用 generateMetadata(异步)以改善 SEO 和社交分享。这会替代旧的 Head 组件。

  • 包体积:使用 @next/bundle-analyzer 分析包体积。精简大型库;使用支持 ESM 树摇 的依赖。

  • 组件:对初始渲染不需要的大型组件使用 dynamic 导入(Next.js 版的 React.lazy)配合 Suspense。

  • Next.js 15+ 集成:在 next.config.js 中启用 ppr: true(部分预渲染),以将静态外壳与动态岛屿结合。

  • 策略:通过 next/font 自托管 Google 字体或本地文件。

  • 优化:零布局偏移,运行时无需为字体文件发起网络请求。将类应用于 <body> 或特定元素。

元数据(SEO)

  • 静态:从 layout.tsx 或 page.tsx 导出 metadata 对象。

    export const metadata: Metadata = {
      title: 'Dashboard',
      description: '...',
    };
    
  • 动态:导出 generateMetadata({ params }) 函数。

    export async function generateMetadata({ params }) {
      const product = await getProduct(params.id);
      return { title: product.name };
    }
    
  • Open Graph:使用 openGraph 键实现社交卡片。

脚本(next/script)

  • 加载策略:控制第三方脚本的加载时机。
    • strategy="afterInteractive"(默认):Google Analytics。
    • strategy="lazyOnload":聊天小部件,低优先级。

反模式

  • 不要使用 <img> 标签:使用 next/image 以防止 CLS 并启用自动优化。
  • 不要使用 Google Fonts CDN 链接:使用 next/font 自托管并消除布局偏移。
  • 不要在 _document.tsx 中放置元数据:使用 export const metadata 或 generateMetadata()。
  • 不要在 <head> 中放置第三方脚本:使用 next/script 并选择合适的 strategy。

Individual skills in this repo

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

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能