defer-async
它能做什么
这项技能检查网页 HTML 中脚本的加载方式。适合希望页面更快呈现的开发者。
适用场景
- ✓当页面在脚本下载期间显示空白时。
- ✓当 head 中的脚本标签拖慢了首次显示时。
- ✓当你希望在慢速网络上页面更快开始显示时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/defer-async/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能检查一下我页面的脚本标签,确保它们不会拖慢加载吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出会阻塞页面的脚本标签,并在安全的地方添加 defer 或 async。对于合适的脚本,它还可以改为 module 类型。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Load scripts with defer, async, or type=module
A plain <script> tag in the document head blocks all HTML parsing until the script downloads, parses, and executes. On a slow network this can add seconds of white-screen time before any content renders. defer and async allow the browser to continue parsing HTML while the script downloads, reducing Time to First Contentful Paint dramatically.
Quick Reference
- defer downloads in parallel and executes after HTML parsing, in order — use for most scripts
- async downloads in parallel and executes immediately when ready — use for independent scripts
- type=module always defers and enables ES module syntax
- Never place scripts in <head> without defer or async
Check
Find all script tags in this HTML file. Flag any in the <head> without defer or async, and any at the bottom of <body> that could be in <head> with defer.
Fix
Add defer or async to script tags in the document head, or convert to type=module where ES modules are used.
Explain
Explain the difference between defer, async, and type=module script loading, and when to use each.
Code Review
Review templates, server-rendered HTML, and shared components that output markup related to Load scripts with defer, async, or type=module. Flag exact elements, attributes, and routes where the rendered HTML violates the rule.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/html/defer-async
常见问题
defer 和 async 有什么区别?
defer 会在页面读取完成后按顺序运行脚本;async 则在脚本下载完成后立即运行,不保证顺序。
我应该使用哪一个?
这项技能建议大多数脚本使用 defer,互不依赖的脚本使用 async。
这适用于框架网站吗?
这项技能说明,要检查浏览器最终收到的 HTML,而不只是源模板。
详情
作者的原始描述
Use when reviewing templates, rendered HTML, or shared components related to Load scripts with defer, async, or type=module. Validate the final browser-facing markup, not just the source framework abstraction.
热度
- GitHub 星标
- 75k
- 排名
- #2812
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。