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

import-on-visibility

它能做什么

这项技能审查长页面和信息流中在可见之前就已加载的大型部分。适用于构建内容丰富页面的开发者。

适用场景

  • ✓当长页面加载了大多数访客从未滚动到的图表或评价的时候。
  • ✓当信息流或仪表盘为位于页面下方很远处的面板加载代码的时候。
  • ✓当大型部分出现导致滚动变得卡顿的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/import-on-visibility/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请只在访客滚动到附近时才加载我页面中的评价部分。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会找出提前加载的屏幕外组件,并建议在它们接近可视区域时通过 Intersection Observer 加载。它还会建议使用占位内容,使布局不会跳动。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Load non-critical code when content approaches the viewport

Many pages ship JavaScript for offscreen sections that a user may never reach. Import-on-visibility keeps the initial route lighter while still loading content early enough to feel ready when users scroll to it.

Quick Reference

  • Use Intersection Observer to start loading code before an offscreen section becomes visible
  • Reserve space with placeholders or skeletons so deferred sections do not cause layout shift
  • Tune rootMargin so heavy content loads early enough without competing with above-the-fold work
  • Use this for charts, reviews, related products, embeds, and offscreen dashboards

Check

Identify components, widgets, or modules that load on first render even though they only appear after the user scrolls. Flag which ones can switch to visibility-based loading.

Fix

Use Intersection Observer or an equivalent framework primitive to load the offscreen component or dependency when it approaches the viewport, while preserving layout stability and a clear placeholder.

Explain

Explain import-on-visibility, how it differs from import-on-interaction, and how viewport-based loading helps large pages stay fast.

Code Review

Inspect scroll-triggered sections, embeds, charts, recommendation modules, and long landing pages. Flag code that is bundled eagerly even though the corresponding UI stays offscreen until later, and verify the deferred version still loads before the user reaches it.


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

Rule page: https://frontendchecklist.io/rules/performance/import-on-visibility

常见问题

什么是 Intersection Observer?

它是一种浏览器功能,用于在元素接近或进入可见区域时进行通知。

这与点击时加载有什么不同?

这种方式是在该部分接近屏幕时加载代码,而点击加载则是等待访客的操作。

为什么要使用占位内容?

这项技能指出,占位内容能保持布局稳定,使延迟加载的部分不会造成布局偏移。

详情

作者的原始描述

Use when reviewing long pages, dashboards, or content feeds with expensive offscreen modules. Balance early enough loading for smooth scrolling against keeping the initial route light.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能