A Next.js helper for creating cache-effective SSR pages with minimal effort (v1.8.0). It simplifies generating regeneratable static-like pages (e.g., sitemaps) with effective caching via Cache-Control headers and built-in protection against bandwidth attacks by stripping query parameters that defeat caching. Key differentiators: zero dependencies, lightweight (small bundle size), works with Next.js >=9, ships TypeScript types, and allows whitelisting specific query params. Release cadence is irregular, latest update 2024.
npm install next-cache-effective-pagesNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a cache-effective sitemap page that revalidates every 15 minutes with bandwidth attack protection.
Pass options via `{...ctx, options: {...}}` instead of `withCacheEffectivePage(fn)(ctx, options)`.Always provide `secondsBeforeRevalidation` for predictable caching.
Add required param names to `allowedQueryParams` array in options.
Ensure the page component is default-exported (e.g., `export default function Sitemap() {}`).Use `import { withCacheEffectivePage } from 'next-cache-effective-pages'` in an ES module.Ensure the callback calls `res.end()` or returns a result that resolves to a valid props object.
Add `options: { secondsBeforeRevalidation: <number> }` to the context object.