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

debounce-throttle

它能做什么

这项技能检查响应滚动、调整大小或输入等快速操作的网站代码。适合希望页面更流畅的开发者。

适用场景

  • ✓当搜索框在有人输入时发送过多请求时。
  • ✓当滚动或调整页面大小感觉卡顿时。
  • ✓当你的脚本运行频率远高于实际需要时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

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

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能