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

defer-async

它能做什么

这项技能检查网页 HTML 中脚本的加载方式。适合希望页面更快呈现的开发者。

适用场景

  • ✓当页面在脚本下载期间显示空白时。
  • ✓当 head 中的脚本标签拖慢了首次显示时。
  • ✓当你希望在慢速网络上页面更快开始显示时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

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

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能