code-splitting
它能做什么
这项技能检查大型脚本是否在每个页面都被加载,即使有些页面只是偶尔才需要它们。适合构建单页应用、并希望首次加载更快的开发者。
适用场景
- ✓当网页应用的 JavaScript 包很大、启动缓慢时。
- ✓当图表、编辑器或其他大型库被加载到从不使用它们的页面上时。
- ✓当你添加一个可以稍后再加载的新依赖时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/code-splitting/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的应用在每个页面都加载了一个很大的图表库。请把它拆分开,让它只在出现图表的页面加载。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把大型的静态导入改为动态 import 调用,按路由拆分代码,并添加加载状态,使代码加载期间页面仍然可用。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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
常见问题
动态 import 有什么作用?
这项技能说明,它只在真正需要时才加载代码,而不是在一开始就全部加载。
应该先拆分什么?
基于路由的部分,以及图表库或富文本编辑器等大型第三方库。
如何看出该拆分什么?
这项技能建议使用可视化工具分析打包结果。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 75k
- 排名
- #2774
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。