Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2774

code-splitting

Skill này làm gì

Skill này kiểm tra xem các script nặng có được tải trên mọi trang dù chỉ thỉnh thoảng mới cần hay không. Skill dành cho lập trình viên xây ứng dụng một trang muốn lần tải đầu nhanh hơn.

Khi nào nên dùng

  • ✓Khi bundle JavaScript của ứng dụng web lớn và khởi động chậm.
  • ✓Khi một biểu đồ, trình soạn thảo hoặc thư viện nặng được tải trên các trang không dùng đến nó.
  • ✓Khi bạn thêm một phụ thuộc có thể tải về sau.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/code-splitting/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/code-splitting/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Ứng dụng của tôi tải một thư viện biểu đồ lớn trên mọi trang. Hãy chia nó để chỉ tải ở nơi có biểu đồ.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent chuyển các import tĩnh nặng thành lời gọi import động, chia code theo route và thêm trạng thái tải để trang vẫn dùng được khi code đang về.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Split large JavaScript bundles

A 500 KB JavaScript bundle blocks page interactivity for 3–5 seconds on a mid-range mobile device even after the bytes arrive — JS must be parsed and compiled before execution. Code splitting means users only download and parse the code they actually need for the current page, dramatically improving Time to Interactive.

Quick Reference

  • Use dynamic import() to load code only when it's actually needed
  • Split routes in SPAs so each page loads only its own code
  • Lazy-load heavy third-party libraries (chart libraries, rich text editors)
  • Analyze your bundle with a visualizer to find what to split

Check

Identify any large third-party imports or feature modules in this file that could be loaded lazily with dynamic import() instead of statically.

Fix

Convert the identified static imports to dynamic imports using import() and add appropriate loading states.

Explain

Explain JavaScript code splitting, how dynamic import() works, and how to implement route-based splitting in a SPA.

Code Review

Inspect route modules, heavy feature imports, and third-party libraries loaded on initial render. Flag dependencies that can move behind import(), route boundaries, or user-triggered flows without breaking the first meaningful paint.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/code-splitting

Câu hỏi thường gặp

Dynamic import làm gì?

Skill nói nó chỉ tải code khi thật sự cần, thay vì tải ngay từ đầu.

Nên chia phần nào trước?

Các phần theo route và thư viện bên thứ ba nặng, chẳng hạn thư viện biểu đồ hoặc trình soạn thảo văn bản giàu định dạng.

Làm sao biết nên chia phần nào?

Skill gợi ý phân tích bundle bằng công cụ trực quan hóa.

Chi tiết

Mô tả gốc của tác giả

Use when reviewing large SPA bundles, new dependency additions, or routes that feel slow to hydrate. Focus on code that is not required for the initial view and can move behind route transitions, user interaction, or viewport-based loading.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2774
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự