---
title: "Build Cache"
description: "Persist prerendered OG images across CI deployments to avoid regenerating unchanged images."
canonical_url: "https://nuxtseo.com/docs/og-image/guides/build-cache"
last_updated: "2026-05-06T18:45:03.741Z"
---

For CI/CD environments, you can enable persistent build caching to skip regenerating images when the output would be identical between deployments.

## Setup

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  ogImage: {
    buildCache: true
  }
})
```

This stores rendered images in `node_modules/.cache/nuxt-seo/og-image/` during prerendering.

<callout icon="i-heroicons-information-circle">

When using [pnpm](https://pnpm.io), this will be in the `node_modules/.pnpm` directory's cache structure. Consider using a [custom cache directory](#custom-cache-directory) for consistency.

</callout>

## Invalidation

The cache automatically invalidates when:

- **Options change**: different title, description, or other props
- **Template changes**: the component file is modified
- **Module version changes**: you upgrade `nuxt-og-image`

## Automatic Cleanup

After each prerender, orphaned cache files (images no longer generated) are automatically cleaned up if they're older than 7 days. This prevents unbounded cache growth while preserving images that social platforms may still be referencing.

## CI Configuration

To persist the cache between CI runs, add the cache directory to your CI configuration:

<code-group>

```yaml [GitHub Actions]
- name: Cache OG Images
  uses: actions/cache@v4
  with:
    path: node_modules/.cache/nuxt-seo
    key: og-images-${{ github.ref_name }}
```

```yaml [GitLab CI]
cache:
  paths:
    - node_modules/.cache/nuxt-seo/
```

</code-group>

## Custom Cache Directory

You can customize the cache location:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  ogImage: {
    buildCache: {
      base: '.cache/og-image'
    }
  }
})
```
