---
title: "content.snapshot()"
description: "Every parsed file plus a freshness stamp, ready to store."
canonical_url: "https://content.comark.dev/reference/content/snapshot"
---
# content.snapshot()

> Every parsed file plus a freshness stamp, ready to store.

## `content.snapshot()`{lang="ts"}

Ensures the instance holds full state, then returns every parsed file with a freshness stamp. This is the data a [snapshot source](https://content.comark.dev/sources/snapshot) hydrates from.

```ts [snapshot.ts]
const { items, time } = await content.snapshot()

items.length // every document and media entry
items[0].path // '/about'
items[0].nodes // the parsed body
time // epoch ms the index was produced
```

### Returns

`Promise<{ items: ContentFile[]; time?: number }>`{lang="ts"} — full [`ContentFile`](https://content.comark.dev/reference/types/content#contentfiletdata-tmeta) entries, bodies included.

Media entries appear with their listing data and an empty `nodes` array, but their bytes aren't part of a snapshot. Ship the bytes separately or keep a raw origin available; the [media plugin](https://content.comark.dev/plugins/built-in/media) can't read bytes from snapshot data alone.

## Storing it

```ts [build.ts]
await useStorage('snapshots').set('content.json', await content.snapshot())
```

A consumer then reads it back through a [snapshot source](https://content.comark.dev/sources/snapshot):

```ts [runtime.ts]
comarkContent({
  source: snapshot(() => useStorage('snapshots').get('content.json')),
})
```

The [`comark-content snapshot`](https://content.comark.dev/reference/cli#comark-content-snapshot) command does the same for a whole project, one directory per instance.

## Serving the current state

This method reports what the instance holds now; it does not re-read the source. Call [`refresh()`](https://content.comark.dev/reference/content/refresh) first when you need to capture changes that landed after initialization:

```ts [rebuild.ts]
await content.refresh()
const snapshot = await content.snapshot()
```

::note
`comark-content snapshot` and [`writeSnapshots()`](https://content.comark.dev/reference/cli#comark-content-snapshot-in-a-build-script) rebuild from the source of truth for you, so a warm development instance cannot leak stale data into a build.
::

## Cost

A snapshot carries every parsed document body, so producing it reads one cache entry per document. The method returns plain data. When you serve it over HTTP, [`content.handler()`](https://content.comark.dev/reference/content/handler) serializes and compresses that data once per content change.


## Sitemap

See the full [sitemap](https://content.comark.dev/sitemap.md) for all pages.
