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.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
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
srcsetwith width descriptors (400w,800w) to all images wider than ~100px - Always pair
srcsetwidth descriptors with asizesattribute—withoutsizesthe browser assumes100vw - Use density descriptors (
1x,2x) only for fixed-size images like avatars and icons - Keep
srcpointing to a fallback size for browsers that don't supportsrcset
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.
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.
Độ 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
Bình luận
- …
Thêm skill từ kho mã này
frontendchecklist
75kKiểm tra mã frontend và trang trực tiếp theo hơn 380 quy tắc về khả năng tiếp cận, tốc độ, SEO và bảo mật, bằng một công cụ dòng lệnh.
frontend-checklist-global
75kKiểm toán một dự án frontend theo đủ 386 quy tắc của Front-End Checklist, và đưa cách sửa cụ thể cho từng vấn đề tìm thấy.
404-page
75kKiểm tra xem trang báo thiếu của bạn có đưa ra các liên kết hữu ích và trả về mã trạng thái 404 thật hay không, để giúp khách bị lạc tìm đường.
about-page
75kKiểm tra xem trang web có trang Giới thiệu rõ ràng giải thích ai điều hành nó hay không, để xây dựng niềm tin với khách và công cụ tìm kiếm.
Skill tương tự
gifgrep
394kCho phép agent của bạn tìm thư viện GIF, xem trước kết quả, tải một GIF, và lấy một khung hình tĩnh hoặc bảng ghép nhiều khung hình.
meme-maker
394kCho phép agent của bạn chọn một mẫu meme, thêm chú thích của riêng bạn và tạo meme dưới dạng ảnh SVG hoặc PNG.
ios-icon-gen
280kGiúp agent tạo biểu tượng cho ứng dụng iOS. Dùng biểu tượng của Apple hoặc từ các nguồn khác để tạo đúng định dạng tệp.