nextjs-best-practices – skill Dữ liệu & Khoa học cho agent AI
Nguyên tắc App Router của Next.js. Server Components, lấy dữ liệu, các mẫu định tuyến.
Cài skill nextjs-best-practices bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/nextjs-best-practices-f5597.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /nextjs-best-practices – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/nextjs-best-practices-f5597.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $nextjs-best-practices – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/nextjs-best-practices-f5597.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /nextjs-best-practices – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/nextjs-best-practices-f5597.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /nextjs-best-practices – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Next.js Best Practices
> Principles for Next.js App Router development.
---
1. Server vs Client Components
Decision Tree
Does it need...?
│
├── useState, useEffect, event handlers
│ └── Client Component ('use client')
│
├── Direct data fetching, no interactivity
│ └── Server Component (default)
│
└── Both?
└── Split: Server parent + Client childBy Default
| Type | Use |
|------|-----|
| Server | Data fetching, layout, static content |
| Client | Forms, buttons, interactive UI |
---
2. Data Fetching Patterns
Fetch Strategy
| Pattern | Use |
|---------|-----|
| Default | Version/config dependent; current fetch defaults are uncached |
| Explicit cache | fetch(url, { cache: "force-cache" }) when data may be shared |
| Revalidate | ISR (time-based refresh) |
| No-store | Dynamic (every request) |
Data Flow
| Source | Pattern |
|--------|---------|
| Database | Server Component fetch |
| API | fetch with caching |
| User input | Client state + server action |
---
3. Routing Principles
File Conventions
| File | Purpose |
|------|---------|
| page.tsx | Route UI |
| layout.tsx | Shared layout |
| loading.tsx | Loading state |
| error.tsx | Error boundary |
| not-found.tsx | 404 page |
Route Organization
| Pattern | Use |
|---------|-----|
| Route groups (name) | Organize without URL |
| Parallel routes @slot | Multiple same-level pages |
| Intercepting (.) | Modal overlays |
---
4. API Routes
Route Handlers
| Method | Use |
|--------|-----|
| GET | Read data |
| POST | Create data |
| PUT/PATCH | Update data |
| DELETE | Remove data |
Best Practices
- Validate input with Zod
- Return proper status codes
- Handle errors gracefully
- Choose Node.js or Edge runtime according to dependency and deployment support; do not assume Node APIs are available on Edge
---
5. Performance Principles
Image Optimization
- Use next/image component
- Set priority for above-fold
- Provide blur placeholder
- Use responsive sizes
Bundle Optimization
- Dynamic imports for heavy components
- Route-based code splitting (automatic)
- Analyze with bundle analyzer
---
6. Metadata
Static vs Dynamic
| Type | Use |
|------|-----|
| Static export | Fixed metadata |
| generateMetadata | Dynamic per-route |
Essential Tags
- title (50-60 chars)
- description (150-160 chars)
- Open Graph images
- Canonical URL
---
7. Caching Strategy
Cache Layers
| Layer | Control |
|-------|---------|
| Request | fetch options |
| Data | revalidate/tags |
| Full route | route config |
Revalidation
| Method | Use |
|--------|-----|
| Time-based | revalidate: 60 |
| On-demand | revalidatePath/Tag |
| No cache | no-store |
---
8. Server Actions
Use Cases
- Form submissions
- Data mutations
- Revalidation triggers
Best Practices
- Mark with 'use server'
- Authenticate and authorize each action/handler on the server; exported actions are callable endpoints
- Validate all inputs
- Return typed responses
- Handle errors
---
9. Anti-Patterns
| ❌ Don't | ✅ Do |
|----------|-------|
| 'use client' everywhere | Server by default |
| Fetch in client components | Fetch in server |
| Skip loading states | Use loading.tsx |
| Ignore error boundaries | Use error.tsx |
| Large client bundles | Dynamic imports |
---
10. Project Structure
app/
├── (marketing)/ # Route group
│ └── page.tsx
├── (dashboard)/
│ ├── layout.tsx # Dashboard layout
│ └── page.tsx
├── api/
│ └── [resource]/
│ └── route.ts
└── components/
└── ui/---
> Remember: Server Components are the default for a reason. Start there, add client only when needed.
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Version scope
Check the installed Next.js version and whether Cache Components is enabled before applying caching advice. The [official caching guide](https://nextjs.org/docs/app/guides/caching) distinguishes these models. Test freshness and invalidation explicitly; never put user-specific secrets or authorization-dependent responses into a shared cache.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Skill liên quan
- ontoly-software-graph – Dùng Software Graph xác định, máy chủ MCP và các skill của agent từ Ontoly để review…
- pangolinfo-amazon-data-research – Lập kế hoạch và thực hiện nghiên cứu chỉ đọc về sản phẩm, đánh giá, danh mục, người bán…
- pci-compliance – Rà soát luồng dữ liệu thanh toán và bằng chứng kiểm soát kỹ thuật cho đánh giá PCI trong…
- pci-dss-compliance – Triển khai các yêu cầu PCI DSS đối với dữ liệu thẻ thanh toán. Cấu hình môi trường chứa…
- people-data – Tra cứu hồ sơ LinkedIn chuyên nghiệp và dữ liệu liên hệ kinh doanh công khai, bao gồm…
- performance-profiling – Nguyên tắc profiling hiệu năng. Kỹ thuật đo lường, phân tích và tối ưu.
- plotly – Thư viện trực quan hóa tương tác. Dùng khi cần hover, zoom, pan hoặc biểu đồ nhúng được…
- project-state-governor – Quản lý trạng thái dự án chuẩn, có bằng chứng xác thực, xuyên suốt các phiên làm việc…