import-on-visibility
它能做什么
这项技能审查长页面和信息流中在可见之前就已加载的大型部分。适用于构建内容丰富页面的开发者。
适用场景
- ✓当长页面加载了大多数访客从未滚动到的图表或评价的时候。
- ✓当信息流或仪表盘为位于页面下方很远处的面板加载代码的时候。
- ✓当大型部分出现导致滚动变得卡顿的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/import-on-visibility/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 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
rootMarginso 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.
热度
- GitHub 星标
- 75k
- 排名
- #2889
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。