debounce-throttle
它能做什么
这项技能检查响应滚动、调整大小或输入等快速操作的网站代码。适合希望页面更流畅的开发者。
适用场景
- ✓当搜索框在有人输入时发送过多请求时。
- ✓当滚动或调整页面大小感觉卡顿时。
- ✓当你的脚本运行频率远高于实际需要时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/debounce-throttle/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能检查我的滚动和输入处理程序是否造成卡顿吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出在快速事件上运行的代码,并建议使用 debounce 或 throttle。debounce 会等到操作停止后再执行,而 throttle 会限制代码的执行频率。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Debounce and throttle event handlers
High-frequency events fire hundreds of times per second, causing UI jank, excessive API calls, and poor Interaction to Next Paint (INP) scores.
Quick Reference
- Debounce: delays execution until activity stops (search inputs, form validation)
- Throttle: limits execution rate (scroll, resize handlers)
- Use 150-300ms delay for user input, 100ms for scroll/resize
- Clean up event listeners to prevent memory leaks
Check
Review this JavaScript code for scroll, resize, input, mousemove, or other high-frequency event handlers that should use debounce or throttle.
Fix
Add debounce or throttle to high-frequency event handlers to limit execution rate and improve performance.
Explain
Explain the difference between debounce and throttle, and when to use each pattern for optimal performance.
Code Review
Review scripts, client components, and browser execution paths related to Debounce and throttle event handlers. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/debounce-throttle
常见问题
debounce 和 throttle 有什么区别?
debounce 会等到用户停顿后才执行;throttle 则在操作持续进行时,以稳定、受限的频率执行代码。
它建议多长的延迟?
这项技能建议输入时约 150 到 300 毫秒,滚动和调整大小时约 100 毫秒。
为什么要清理事件监听器?
这项技能说明,清理监听器可以防止内存泄漏,避免页面随时间越来越慢。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Debounce and throttle event handlers. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #2810
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。