跳到正文
Skillpedia
网站与界面(前端)75k · #2774

code-splitting

它能做什么

这项技能检查大型脚本是否在每个页面都被加载,即使有些页面只是偶尔才需要它们。适合构建单页应用、并希望首次加载更快的开发者。

适用场景

  • ✓当网页应用的 JavaScript 包很大、启动缓慢时。
  • ✓当图表、编辑器或其他大型库被加载到从不使用它们的页面上时。
  • ✓当你添加一个可以稍后再加载的新依赖时。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/code-splitting/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2774
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能