Sample and Memory
First visit
There's no real data yet, so sample sets the shape. If the real text turns out longer or shorter, the block eases to its new height. Matching the size exactly on a first visit isn't possible: nobody knows the length of the response yet.
Here the sample is shorter than the real post, so the block grows when the response arrives:
<script setup lang="ts">
const post = useFetch<Post>('https://dummyjson.com/posts/3?delay=1500', {
lazy: true,
server: false,
})
const sample: Post = {
title: 'A short sample title',
body: 'A sample body that is a good deal shorter than the post the server is about to send.',
}
</script>
<template>
<Skeleton :of="post" :sample :persist="false">
<template #default="{ data }">
<h4>{{ data.title }}</h4>
<p>{{ data.body }}</p>
</template>
</Skeleton>
</template>
If the data can be fetched on the server, remove server: false. The content then arrives in the HTML and no skeleton is needed.
Later visits
The shape of the last content is saved in localStorage and applied before the first paint. Memory is kept per id, which defaults to the page plus the order skeletons appear on it. Give an id to a skeleton that mounts and unmounts while the page stays, such as one inside tabs.
A shape is only used at the same window width. At another width the text would wrap differently, so the sample is used again. If the layout depends on something else too, such as the window height or a setting, put that into the id: :id="`shelf:${rows}`".
Besides text and blocks, memory keeps the outlines of the layout: borders, dividers, and the fill of cards and panels in their own colors. A surface drawn with a gradient or an image is kept only when it's marked with data-skeleton-block.
This example has no sample at all. The first load shows generic lines, and every load after it uses the remembered shape. Below it is exactly what's stored:
Nothing remembered yet<script setup lang="ts">
const post = useFetch<Post>('https://dummyjson.com/posts/5?delay=1500', {
lazy: true,
server: false,
})
</script>
<template>
<Skeleton id="docs-memory" :of="post">
<template #default="{ data }">
<h4>{{ data.title }}</h4>
<p>{{ data.body }}</p>
</template>
</Skeleton>
</template>
What's stored
Geometry only: fractions of the width and heights in pixels, for up to 50 shapes. No text, markup or attributes.
Turning it off and clearing it
<Skeleton :persist="false" />
export default defineNuxtConfig({
boneprint: { persist: false },
})
app.use(boneprint, { persist: false })
On sign-out, call forgetSkeletons(). Memory is cleared, and whatever is on screen won't be written back.