scheduler-yield
它能做什么
这个技能找出可能冻结页面的长时间 JavaScript 循环和递归工作,并添加暂停点,让浏览器能够响应。它面向在大量处理时页面显得卡住的前端开发者。
适用场景
- ✓你请智能体防止页面在处理大量数据时冻结的时候。
- ✓应用中的繁重任务执行时,点击或输入感觉延迟的时候。
- ✓你审查带有大循环或大量 DOM 更新的代码,并希望保持界面响应的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/scheduler-yield/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的页面处理大列表时会卡住一会儿。请帮我把这些工作拆分开,让页面保持响应吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出可能超过约 50 毫秒的循环和批量操作。它会重构这些代码,使其在各块之间使用 scheduler.yield 暂停;如果该函数不可用,则使用备用方案。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use scheduler.yield() to keep the main thread responsive during long tasks
Any JavaScript task longer than 50 ms blocks the browser's main thread, preventing it from processing clicks, keyboard events, and rendering frames. Yielding between chunks of work keeps Interaction to Next Paint (INP) low and makes the page feel responsive even during heavy computation.
Quick Reference
- Tasks longer than 50 ms block input and hurt Interaction to Next Paint (INP)
- scheduler.yield() pauses execution, lets the browser handle queued input, then resumes
- Use a MessageChannel-based polyfill where scheduler.yield() is unavailable
- Apply to data processing loops, tree traversals, and bulk DOM mutations
Check
Identify synchronous loops, recursive traversals, or bulk operations in this code that could run for more than 50 ms and block user input.
Fix
Refactor long synchronous tasks to yield to the browser between chunks using scheduler.yield() with a MessageChannel fallback.
Explain
Explain why tasks longer than 50 ms hurt INP, how scheduler.yield() works, and when to use it versus Web Workers.
Code Review
Review event handlers, data transformation functions, and initialization routines for synchronous loops over large collections that could block input. Flag any loop where the total work could exceed 50 ms.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/scheduler-yield
常见问题
为什么 50 毫秒很重要?
这个技能说,超过 50 毫秒的任务会占用主线程,可能延迟点击和渲染。
什么时候应改用 Web Workers?
这个技能提到可以把 scheduler.yield 与 Web Workers 进行比较,后者会把工作移到主线程之外。
这对响应速度有什么影响?
这个技能说,它有助于降低 Interaction to Next Paint,使页面在繁重工作时感觉更流畅。
详情
作者的原始描述
Use when reviewing JavaScript that performs synchronous loops over large datasets, recursive tree traversals, or bulk DOM updates that may exceed 50 ms on mid-range devices.
热度
- GitHub 星标
- 75k
- 排名
- #3007
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。