offscreen-lazy
它能做什么
这个技能检查页面上的图片标签,并为屏幕外的图片添加懒加载,同时让首屏主图立即加载。它面向希望首次加载更快的网站构建者。
适用场景
- ✓你请智能体加快一个一次加载大量图片的页面的时候。
- ✓长页面下载了很多访客可能永远不会滚动到的照片的时候。
- ✓你在审查图片标记,并想确认主图没有被误设为懒加载的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/offscreen-lazy/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的长商品页一次加载了太多图片。请帮我为首屏以下的图片添加懒加载吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查每个图片标签,并为首屏以下的图片添加原生懒加载属性。它会保留主图的即时加载,并建议添加 width 和 height 属性,以避免布局偏移。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Lazy load offscreen images
Lazy loading eliminates unnecessary image downloads on initial page load. A page with 20 images below the fold may transfer several megabytes of data that users who don't scroll will never see. Deferring these downloads reduces Time to Interactive, improves LCP for above-fold content, and saves bandwidth—particularly impactful for users on metered mobile connections.
Quick Reference
- Add
loading="lazy"to all<img>elements below the fold - Never lazy-load the LCP image (hero, first product image)—use
fetchpriority="high"instead - Always pair
loading="lazy"withwidthandheightattributes to prevent CLS - Native
loading="lazy"has universal support in all modern browsers—no JavaScript polyfill needed - If fold position is unclear from the snippet, do not invent a lazy-loading defect
Check
Scan all <img> elements in this codebase. Identify: 1) Any <img> elements below the fold (not in the first viewport) that are missing loading="lazy". 2) Any <img> elements marked loading="lazy" that appear to be above the fold (hero images, first product images, logos in headers). 3) Any <img> with loading="eager" below the fold. Report the above-fold images that should NOT have lazy loading separately from below-fold images that should have it. If fold position cannot be inferred from the snippet, do not report missing lazy loading as a defect.
Fix
For images that should use lazy loading: 1) Add loading="lazy" to all <img> elements that appear below the fold. 2) Remove loading="lazy" from any hero, logo, or first-visible image—these should load immediately. 3) Ensure all lazy-loaded images have explicit width and height attributes to prevent CLS. 4) For the LCP image specifically, add fetchpriority="high" and remove loading="lazy". Show the corrected HTML for each modified image.
Explain
Explain how native browser lazy loading works. The loading="lazy" attribute tells the browser to defer image download until the image is within a browser-defined distance from the viewport (typically 1250px on a slow connection). This reduces the data transferred on initial load, lowers Time to Interactive, and saves bandwidth for users who never scroll to those images. Browser support is universal in modern browsers. The critical caveat: never lazy-load the LCP image—it must load as fast as possible.
Code Review
Review image assets, markup, and delivery configuration related to Lazy load offscreen 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/offscreen-lazy
常见问题
为什么主图不应该懒加载?
主图通常是最大的可见元素,延迟加载会拖慢主要内容,因此这个技能建议为它设置 fetchpriority 为 high。
我需要 JavaScript 库来实现吗?
不需要。这个技能说,所有现代浏览器都支持原生懒加载,无需 polyfill。
如果无法确定图片是否在屏幕外怎么办?
这个技能说,除非图片明显位于屏幕外或不重要,否则不要报告缺少懒加载的问题。
详情
作者的原始描述
Use when reviewing image assets, markup, and CDN or build transforms related to Lazy load offscreen images. Check encoded size, rendered size, loading strategy, and above-the-fold impact together. Missing `loading='lazy'` is only a valid finding when you can reasonably tell the image is offscreen or non-critical.
热度
- GitHub 星标
- 75k
- 排名
- #2958
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。