import-on-visibility — Claude Code skill: lazy loading on scroll
A skill that teaches the agent to defer components and images until the user scrolls them into view. Useful when your first paint is dragging.
npx skills add PatternsDev/skills --skill import-on-visibility -a claude-codeWhat import-on-visibility does
The skill covers import on visibility: a module or image loads only once it enters the viewport. Detection runs through IntersectionObserver, or through libraries such as react-lazyload and react-loadable-visibility. While the module is on its way, a fallback component renders so the page doesn't look frozen.
What you get is guidance for the agent, not a drop-in snippet. It points out where the observer belongs, how to wire up a library, and what to show in place of the pending block. The skill lives in SKILL.md and applies to **/*.js and **/*.ts.
The catch is above-the-fold content. Deferring anything that must render immediately causes visible layout shifts and slow LCP, so keep the hero out of it. Lightweight components rarely pay off either — the overhead outweighs the savings. Content that matters for SEO has to sit in the initial HTML.
What it helps with
- defer below-the-fold blocks until scroll
- speed up first paint on pages with heavy widgets
- wire up
IntersectionObserverfor viewport detection - render a fallback while a module loads
- keep images out of the initial request
Example prompts for the agent
- Lazy load the gallery below the fold with IntersectionObserver
- Why is my hero section shifting when I lazy load it?
- Add react-loadable-visibility for the heavy chart in the footer
How to install import-on-visibility
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill import-on-visibility -a claude-code2Manually: put the files in place
~/.claude/skills/import-on-visibility/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/import-on-visibility/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill import-on-visibility -a codex2Manually: put the files in place
.agents/skills/import-on-visibility/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill import-on-visibility -a cursor2Manually: put the files in place
.cursor/skills/import-on-visibility/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PatternsDev/skills import-on-visibility2Manually: put the files in place
.github/skills/import-on-visibility/SKILL.md1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill import-on-visibility -a gemini-cli2Platform CLI
gemini skills install https://github.com/PatternsDev/skills --path javascript/import-on-visibilityManually: put the files in place
.devin/skills/import-on-visibility/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill import-on-visibility -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about import-on-visibility
How do I install import-on-visibility in Claude?
Run npx skills add PatternsDev/skills --skill import-on-visibility -a claude-code. The skill then sits at ~/.claude/skills/import-on-visibility/SKILL.md.
What does import-on-visibility do?
It teaches the agent to defer imports of components and images until they enter the viewport, using IntersectionObserver or libraries like react-lazyload.
When should I avoid this pattern?
For above-the-fold content: deferring it causes layout shifts and slow LCP. Lightweight components don't benefit either, since the overhead is larger than the saving.
Source text
SKILL.md · MIT
--- name: import-on-visibility description: Teaches visibility-based lazy loading using Intersection Observer. Use when you have below-the-fold components or images that don't need to load until the user scrolls to them. paths: - "**/*.js" - "**/*.ts" license: MIT metadata: author: patterns.dev version: "1.1" related_skills: - "module-pattern" - "singleton-pattern" --- # Import On Visibility Besides user interaction, we often have components that aren't visible on the initial page. A good example of this is lazy loading images that aren't directly visible in the viewport, but only get loaded once the user scrolls down. As we're not requesting all images instantly, we can reduce the initial loading time. We can do the same with components! In order to know whether components are currently in our viewport, we can use the [`IntersectionObserver` API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API), or use libraries such as `react-lazyload` or `react-loadable-visibility` to quickly add import on visibility to our application. ## When to Use - Use this for components that aren't visible on the initial page (e.g., below-the-fold content) - This is helpful for lazy loading images, widgets, or heavy components as the user scrolls ## When NOT to Use - For above-the-fold content that must render immediately — deferring it causes visible layout shifts and slow LCP - When the component is lightweight enough that lazy loading adds more overhead than it saves - When the content is critical for SEO and needs to be present in the initial HTML ## Instructions - Use the `IntersectionObserver` API to detect when components enter the viewport - Use libraries like `react-lazyload` or `react-loadable-visibility` for quick implementation - Provide a loading fallback component while the module is being loaded ## Details Whenever a component is rendered to the screen, `react-loadable-visibility` detects that the element should be visible on the screen. Only then, it will start importing the module while the user sees a loading component being rendered. This fallback component lets the user know that our application hasn't frozen: they simply need to wait a short while for the module to be loaded, parsed, compiled, and executed! ## Source - [patterns.dev/vanilla/import-on-visibility](https://patterns.dev/vanilla/import-on-visibility)
© patterns.dev · MIT · PatternsDev/skills