Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PatternsDev/skills --skill import-on-visibility -a claude-code
Open on GitHub

What 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 IntersectionObserver for 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-code

2Manually: put the files in place

~/.claude/skills/import-on-visibility/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/import-on-visibility/

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

Similar skills

Everything for Frontend and UI →

From the same set44

tree-shaking A skill that teaches the agent tree shaking for JavaScript bundles, so unused exports stop shipping to users. Handy when your build pulls in code nobody calls. CX Codex +1 1,400installs route-based Tells the agent how to split a single-page app by route so only the code for the current page is fetched. Useful when routes are many and the first load drags. CX Codex +1 1,400installs virtual-lists Teaches your coding agent list virtualization and windowing techniques for React. Solves scroll stutter and reduces initial rendering time for heavy datasets. CX Codex +1 1,500installs third-party Walks you through cutting the performance cost of third-party scripts without dropping analytics, ads or widgets. CX Codex +1 1,500installs react-data-fetching Teaches your agent modern React data fetching: parallel requests, caching, deduplication, Suspense. Useful when components still fetch inside useEffect. CX Codex +1 1,100installs react-render-optimization A skill that teaches your agent React rendering patterns: kills unnecessary re-renders, fixes memoization and state design. CX Codex +1 1,100installs presentational-container-pattern Teaches agents the presentational and container pattern to split data fetching from React UI. Useful when isolating state and API calls to simplify testing and component reuse. CX Codex +1 1,100installs react-composition-2026 A skill that pushes your agent away from boolean props and rigid component APIs toward compound components, explicit variants and children. CX Codex +1 1,100installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor