Communitygithub.com

ComeOnOliver/skillshub

Next.js 資源優化策略:使用 next/image、next/font、next/script 和 metadata 來提升圖像、字體、腳本與頁面元資料的效能。

skillshub 是什麼?

此技能專注於 Next.js 應用程式的核心優化策略,包括圖像、字體、腳本、元資料與 bundle 分析。它強調「先監控、後優化」的原則,透過分析 Core Web Vitals(LCP、CLS、INP)來找出效能瓶頸。支援的技術有 `next/image`(自動避免 CLS 並支援 priority 與 blur placeholder)、`next/font`(自託管字體達到零布局偏移)、`next/script`(提供 beforeInteractive、afterInteractive、lazyOnload 三種載入策略),以及靜態或動態的元資料定義(SEO 與開放圖形協定)。此外,本技能建議使用 `@next/bundle-analyzer` 分析套件大小、使用 dynamic imports 搭配 Suspense 減少初始渲染負擔,並在 Next.js 15 以上版本啟用 Partial Prerendering(ppr: true)。最後它也列出常見的反模式,例如直接使用 `<img>` 標籤、Google Fonts CDN 連結、在 \(document\) 中定義元資料或將第三方腳本直接放在 `<head>` 中。

相容平台~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 提供的核心優化原語。先監控,後優化。

監控(核心網頁指標)

在套用優化之前,先透過以下方式找出瓶頸:

  • LCP(最大內容繪製):初始載入速度。目標 < 2.5s。
  • CLS(累計布局偏移):視覺穩定性。目標 < 0.1。
  • INP(與下一次繪製的互動):回應速度。目標 < 200ms。
  • 工具: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(較低優先 / 社交小工具 / 聊天)。

  • 元資料:定義 靜態元資料 或使用 generateMetadata(非同步)處理動態路由,以改善 SEO 與社交分享。這取代了傳統的 Head 元件。

  • 套件:使用 @next/bundle-analyzer 分析套件大小。精簡大型函式庫;使用 ESM-tree-shakable 的依賴項。

  • 元件:對不需要在初始渲染時載入的大型元件,使用 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: '儀表板',
      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

相關技能