Chuyển đến nội dung
Skillpedia
Hình ảnh và biểu tượng75k · #3034

srcset

Skill này làm gì

Skill này kiểm tra các thẻ hình ảnh trên website, thêm thuộc tính srcset và sizes ở chỗ còn thiếu, và sửa những thẻ không khớp với bố cục. Nó dành cho người làm website muốn hình ảnh tải hiệu quả trên mọi thiết bị.

Khi nào nên dùng

  • ✓Khi bạn yêu cầu agent làm cho hình ảnh trên website tải đúng kích thước cho từng thiết bị.
  • ✓Khi điện thoại tải hình ảnh desktop lớn và người xem dùng mạng di động phàn nàn trang chậm.
  • ✓Khi một hình có srcset nhưng thuộc tính sizes không khớp với cách hình được hiển thị.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/srcset/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/srcset/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

“Điện thoại trên website của tôi tải toàn bộ hình ảnh bản desktop. Bạn có thể thêm srcset để mỗi thiết bị nhận một kích thước vừa 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 hình rộng hơn khoảng 100 pixel mà chưa có srcset, rồi tạo các biến thể chiều rộng như 400, 800 và 1200 pixel. Nó thêm danh sách srcset và thuộc tính sizes khớp với bố cục thực tế, đồng thời giữ src dự phòng.

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.

Use srcset for responsive images

Without srcset, every user—regardless of their device—downloads the same large image. A 1600px hero image served to a 375px mobile display downloads 4x the data needed. The srcset attribute lets browsers choose the optimal file automatically, reducing bandwidth by 50-80% for mobile users with no change to visual quality.

Quick Reference

  • Add srcset with width descriptors (400w, 800w) to all images wider than ~100px
  • Always pair srcset width descriptors with a sizes attribute—without sizes the browser assumes 100vw
  • Use density descriptors (1x, 2x) only for fixed-size images like avatars and icons
  • Keep src pointing to a fallback size for browsers that don't support srcset

Check

Scan all <img> elements in this codebase. Flag: 1) Any <img> wider than 100px (in CSS or layout) that lacks a srcset attribute. 2) Any <img> with srcset but missing a sizes attribute (necessary for width descriptors). 3) Any <img> using only density descriptors (1x, 2x) where width descriptors (400w, 800w) would be more appropriate. 4) Any srcset that provides only one size (no benefit over plain src). Report each finding with file path and line number.

Fix

For each <img> missing srcset: 1) Generate multiple width variants: typically 400w, 800w, 1200w (add 1600w for full-bleed images). 2) Add srcset listing each variant with its width descriptor. 3) Add a sizes attribute describing actual CSS layout width at each breakpoint. 4) Keep src pointing to a mid-range size (800w) as the fallback. 5) Add width and height attributes if missing. For each image, show the complete corrected HTML including srcset and sizes.

Explain

Explain how srcset and the two descriptor types work. Width descriptors (400w, 800w) describe the intrinsic width of each candidate; the browser combines this with the sizes attribute to calculate which candidate provides the best pixel density for the current viewport. Density descriptors (1x, 2x) are simpler but less flexible—use them only for fixed-size images like avatars and icons. The sizes attribute is critical: without it, the browser assumes 100vw and always downloads the largest candidate even on narrow screens.

Code Review

Review image assets, markup, and delivery configuration related to Use srcset for responsive images. Flag exact files or components where format choice, sizing, or loading behavior violates the rule, and describe how to confirm the fix in DevTools.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/images/srcset

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

Tại sao sizes lại quan trọng?

Skill cho biết nếu thiếu nó, trình duyệt sẽ cho rằng hình rộng bằng toàn bộ khung nhìn, dẫn tới việc chọn một file quá lớn.

Khi nào nên dùng mô tả mật độ?

Skill cho biết chỉ dùng 1x và 2x cho hình có kích thước cố định như ảnh đại diện và icon.

Điều này có thay đổi giao diện trang không?

Không. Skill cho biết nó giảm dung lượng tải mà không đổi cách hình ảnh hiển thị.

Chi tiết

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

Use when reviewing image assets, markup, and CDN or build transforms related to Use srcset for responsive images. Check encoded size, rendered size, loading strategy, and above-the-fold impact together.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#3034
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ự