import-on-interaction
它能做什么
这项技能审查页面代码中在有人使用之前就已加载的大型功能。适用于希望首次加载更快的开发者。
适用场景
- ✓当聊天小组件或地图每次访问都会加载,但很少有人使用的时候。
- ✓当页面首次加载包含无人打开的编辑器或导出工具的时候。
- ✓当你的初始代码包体远大于首屏所需的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/import-on-interaction/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请只在访客点击打开时,才加载我的聊天小组件。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出只在点击、聚焦或悬停之后才需要的功能,并建议使用动态导入来加载它们。它还会建议在代码加载期间显示即时反馈。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Load non-critical code on user interaction
Users should not pay the download, parse, and execution cost for features they may never use. Import-on-interaction shrinks initial JavaScript, reduces main-thread work during page load, and keeps the first view focused on content that matters immediately.
Quick Reference
- Move non-essential code behind clicks, focus, hovers, or explicit user actions
- Use dynamic import() so the code is absent from the initial route bundle
- Show immediate UI feedback while the deferred chunk loads
- Use this for chat widgets, editors, maps, filters, and export flows that are not needed on first paint
Check
Inspect this route or component for heavy modules, widgets, or third-party scripts that load on first render but are only needed after a user clicks, focuses, hovers, or opens a panel.
Fix
Move the non-critical dependency behind a user-triggered dynamic import(), add immediate loading feedback, and ensure the initial render still works without the deferred feature.
Explain
Explain import-on-interaction, why it improves initial performance, and which features are safe to defer until the user shows intent.
Code Review
Inspect event handlers, modal triggers, drawers, editors, maps, export actions, and third-party widgets. Flag code that is included in the initial bundle even though it is only needed after a user interaction, and verify the fix keeps the initial path lighter without degrading the triggered flow.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/performance/import-on-interaction
常见问题
什么是动态导入?
它只在需要时才加载某段代码,而不是在首次加载页面时加载。
哪些功能可以安全地延迟加载?
这项技能提到聊天小组件、编辑器、地图、筛选器和首屏不需要的导出流程。
没有该功能时页面还能正常工作吗?
这项技能指出,初始渲染在没有延迟加载的功能时仍应能正常工作。
详情
作者的原始描述
Use when reviewing slow initial loads caused by optional features. Prioritize code that is expensive to download or execute and not required for the first viewport, first input, or core task completion.
热度
- GitHub 星标
- 75k
- 排名
- #2888
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。