---
title: "Sample and Memory"
description: "Where the shape comes from on the first and later visits."
canonical_url: "https://kukson777.github.io/boneprint/docs/guide/sample-and-memory"
---
# Sample and Memory

> Where the shape comes from on the first and later visits.

## 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:

<code-preview>
<sample-demo>



</sample-demo>

<template v-slot:code="">

```vue
<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>
```

</template>
</code-preview>

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:

<code-preview>
<memory-demo>



</memory-demo>

<template v-slot:code="">

```vue
<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>
```

</template>
</code-preview>

## 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

```vue
<Skeleton :persist="false" />
```

<code-group>

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  boneprint: { persist: false },
})
```

```ts [main.ts (Vue)]
app.use(boneprint, { persist: false })
```

</code-group>

On sign-out, call `forgetSkeletons()`. Memory is cleared, and whatever is on screen won't be written back.


## Sitemap

See the full [sitemap](https://kukson777.github.io/boneprint/sitemap.md) for all pages.
