Registry / devops / nuxt-cache-ssr

nuxt-cache-ssr

JSON →
library1.1.0jsnpmunverified

A Nuxt 3 module that adds in-memory caching for server-side rendered pages. Version 1.1.0 is current. It allows configuration of cache store (memory, with Redis placeholder), TTL, max cache size, custom cache keys based on route/headers/device, per-environment enabling, and experimental response compression and per-page cache bypass. Limitations include no built-in Redis support (planned), no regex patterns for pages, and a notable security caveat about caching user-specific data. Differentiators: simple integration, device-aware key generation, and experimental features.

npm install nuxt-cache-ssr
INSTALL
IMPORT
SIG · NUXT-CACHE-SSR
N
nuxt-cache-ssr
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

defineNuxtConfig
import { defineNuxtConfig } from 'nuxt/config'
module.exports = { ... }
Define Nuxt config using ESM syntax.
nuxt-cache-ssr module
nuxt-cache-ssr
import NuxtCacheSsr from 'nuxt-cache-ssr'
Use as a string in modules array, not a default import.
Device interface
import type { Device } from 'nuxt-cache-ssr'
const { Device } = require('nuxt-cache-ssr')
The Device type is exported for use in key function; use type import.

Configures nuxt-cache-ssr module with memory store, caching for home, products, and about pages, and a custom key function that differentiates crawlers and uses language header.

import { defineNuxtConfig } from 'nuxt/config'; export default defineNuxtConfig({ modules: [ ['nuxt-cache-ssr', { enabled: process.env.NODE_ENV !== 'development', store: { type: 'memory', max: 500, ttl: 60000 }, pages: ['/', '/products', '/about'], key: (route, headers, device) => { if (device.isCrawler) { return route; } return `${route}:${headers['accept-language'] || 'en'}`; } }] ] });
Debug
Known issues
gotchaDo not cache pages that contain user‑specific data (e.g., secret keys, personal info) because the cache is shared across all users.
fix
Ensure cached pages only contain public content; use the `key` function with `return false` to bypass cache for sensitive routes.
affects: *
deprecatedThe experimental `compress` option is not yet stable and may change or be removed.
fix
Avoid relying on experimental features in production; monitor releases for stable API.
affects: >=1.0.0
gotchaThe `pages` array matches route prefixes (e.g., '/page1' matches '/page1' and '/page1/sub') but does not support regex patterns, which may cause unintended caching.
fix
Use precise prefixes or implement custom key function with route matching logic.
affects: <=1.1.0
gotchaSetting `enabled: false` does not clear the existing cache; cached pages may still be served from previous runs if the server process persists.
fix
Restart the server or manually clear cache (e.g., via module options) when toggling enabled.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'ohash' or its corresponding type declarations.
Ohash is a dependency of the module but may not be automatically installed in some setups.
fix
Run `npm install ohash` or ensure your package manager installs peer dependencies.
TypeError: Cannot read properties of undefined (reading 'userAgent')
The `key` function receives `device` as undefined if the module's device detection fails (e.g., in certain server contexts).
fix
Add a guard in the key function: `if (!device) return route`.
Module 'nuxt-cache-ssr' is not compatible with Nuxt 2.
This module is designed for Nuxt 3 only; using it in Nuxt 2 will cause errors.
fix
Upgrade to Nuxt 3 or use an alternative caching module for Nuxt 2.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
ohashrequiredUsed to hash custom cache keys for storage.
nuxt3requiredRuntime dependency; module requires Nuxt 3 environment.
Agent activity
2 hits · last 30 days
node
2
Resources
nuxt-cache-ssr — npm install nuxt-cache-ssr · libregistry