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

offscreen-lazy

它能做什么

这个技能检查页面上的图片标签,并为屏幕外的图片添加懒加载,同时让首屏主图立即加载。它面向希望首次加载更快的网站构建者。

适用场景

  • ✓你请智能体加快一个一次加载大量图片的页面的时候。
  • ✓长页面下载了很多访客可能永远不会滚动到的照片的时候。
  • ✓你在审查图片标记,并想确认主图没有被误设为懒加载的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 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" with width and height attributes 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.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能