Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2812

defer-async

Skill này làm gì

Skill này kiểm tra cách script được tải trong HTML của trang web. Skill dành cho lập trình viên muốn trang xuất hiện nhanh hơn.

Khi nào nên dùng

  • ✓Khi trang hiển thị màn hình trống trong lúc script đang tải.
  • ✓Khi các thẻ script trong phần head làm chậm lần xem đầu tiên.
  • ✓Khi bạn muốn trang bắt đầu hiện ra sớm hơn trên kết nối chậm.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/defer-async/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể kiểm tra các thẻ script của trang tôi để chúng không làm chậm việc tải không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm các thẻ script đang chặn trang và thêm defer hoặc async khi an toàn. Nó cũng có thể chuyển các script phù hợp sang kiểu module.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Defer và async khác nhau thế nào?

Defer chạy script theo thứ tự sau khi trang được đọc xong. Async chạy mỗi script ngay khi nó tải về, không theo thứ tự nhất định.

Nên dùng cái nào?

Skill khuyên dùng defer cho hầu hết script và async cho các script độc lập.

Điều này có áp dụng cho các site dùng framework không?

Skill nói nên kiểm tra HTML cuối cùng mà trình duyệt nhận được, không chỉ mã nguồn template.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2812
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự