How It Works
auto-skeleton scans your real rendered DOM at runtime — no manual shapes, no CLI step, no JSON files.
Lifecycle
- First render —
loadingisfalse. The real content renders normally so the DOM is measurable. - Scan — A
TreeWalkertraverses every visible element inside<AutoSkeleton>. Each element is measured withgetBoundingClientRectand classified as a rect, circle, or text block. - Cache — Bone positions are stored in memory and
sessionStorage, keyed byid+ viewport width. - Loading state — When
loadingswitches totrue, an absolutely-positioned overlay renders the cached bones over hidden content (visibility: hiddenpreserves layout). - Reveal — When
loadingflips back tofalse, the overlay unmounts and real content reappears.
Bone classification
| Element type | Detected as |
|---|---|
<img> with border-radius: 50% or data-skeleton-shape="circle" | Circle |
<img>, <video>, block elements | Rect |
Text nodes, <p>, <span>, headings | Text lines |
Caching
Bones are cached in two layers:
- Memory (
Map) — instant lookup, cleared on page unload sessionStorage— survives re-renders and hot reloads, keyed asauto-skeleton:{id}::{viewportWidth}
On viewport resize, the cache is invalidated and a fresh scan runs automatically.
Watch mode
When options.watch is true (default), a ResizeObserver watches the container for layout changes and schedules a re-scan with a debounce (default 120ms). This keeps bones accurate when content changes while not loading.