{"id":45547,"library":"next-cache-effective-pages","title":"next-cache-effective-pages","description":"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.","status":"active","version":"1.8.0","language":"javascript","source_language":"en","source_url":"https://github.com/bmstefanski/next-cache-effective-pages","tags":["javascript","nextjs","nextjs-plugin","typescript"],"install":[{"cmd":"npm install next-cache-effective-pages","lang":"bash","label":"npm"},{"cmd":"yarn add next-cache-effective-pages","lang":"bash","label":"yarn"},{"cmd":"pnpm add next-cache-effective-pages","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: required to provide server-side rendering context","package":"next","optional":false},{"reason":"Peer dependency: required by Next.js for page rendering","package":"react","optional":false},{"reason":"Peer dependency: required by Next.js for DOM rendering","package":"react-dom","optional":false}],"imports":[{"note":"ESM-only; package does not export a CommonJS version.","wrong":"const withCacheEffectivePage = require('next-cache-effective-pages')","symbol":"withCacheEffectivePage","correct":"import { withCacheEffectivePage } from 'next-cache-effective-pages'"},{"note":"Type-only import; the interface is not a runtime value.","wrong":"import { WithCacheEffectivePageOptions } from 'next-cache-effective-pages'","symbol":"WithCacheEffectivePageOptions","correct":"import type { WithCacheEffectivePageOptions } from 'next-cache-effective-pages'"},{"note":"Type-only import; the type is not exported as a runtime value.","wrong":"import { CacheEffectivePageResult } from 'next-cache-effective-pages'","symbol":"CacheEffectivePageResult","correct":"import type { CacheEffectivePageResult } from 'next-cache-effective-pages'"}],"quickstart":{"code":"// pages/sitemap.xml.tsx\nimport { withCacheEffectivePage } from 'next-cache-effective-pages';\n\ninterface Ctx {\n  res: import('http').ServerResponse;\n}\n\nexport default function Sitemap() {}\n\nexport async function getServerSideProps(ctx: Parameters<typeof withCacheEffectivePage>[0] extends (args: infer P) => any ? P : never) {\n  return withCacheEffectivePage(async ({ res }: Ctx) => {\n    res.setHeader('Content-Type', 'text/xml');\n    const posts = await fetch('https://api.example.com/posts').then(r => r.json());\n    res.write(`<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset>${posts.map((p: any) => `<url><loc>https://example.com/posts/${p.id}</loc></url>`).join('')}</urlset>`);\n    res.end();\n  })({ ...ctx, options: { secondsBeforeRevalidation: 60 * 15 } });\n}","lang":"typescript","description":"Shows how to create a cache-effective sitemap page that revalidates every 15 minutes with bandwidth attack protection."},"warnings":[{"fix":"Pass options via `{...ctx, options: {...}}` instead of `withCacheEffectivePage(fn)(ctx, options)`.","message":"The function signature changed in v1.0.0: options now must be passed in the context object, not as second argument.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Always provide `secondsBeforeRevalidation` for predictable caching.","message":"The `secondsBeforeRevalidation` option is now optional; defaults to 0 (no cache). In future versions, it may become required.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Add required param names to `allowedQueryParams` array in options.","message":"The library strips all query parameters except those in `allowedQueryParams`. This may break pages relying on query params for logic.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the page component is default-exported (e.g., `export default function Sitemap() {}`).","message":"The exported component must be a default export and named `default`; otherwise, Next.js will not invoke `getServerSideProps`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2024':80 '9':64 'allow':69 'attack':45 'bandwidth':44 'built':40 'built-in':39 'bundl':59 'cach':3,12,32,35,52 'cache-control':34 'cache-effect':11 'cadenc':75 'control':36 'creat':10 'defeat':51 'depend':56 'differenti':54 'e.g':28 'effect':4,13,31 'effort':18 'generat':22 'header':37 'helper':8 'irregular':77 'javascript':81 'key':53 'latest':78 'lightweight':57 'like':26 'minim':17 'next':2 'next-cache-effective-pag':1 'next.js':7,63 'nextj':82,84 'nextjs-plugin':83 'page':5,15,27 'param':73 'paramet':49 'plugin':85 'protect':42 'queri':48,72 'regenerat':23 'releas':74 'ship':65 'simplifi':21 'sitemap':29 'size':60 'small':58 'specif':71 'ssr':14 'static':25 'static-lik':24 'strip':47 'type':67 'typescript':66,86 'updat':79 'v1.8.0':19 'via':33 'whitelist':70 'work':61 'zero':55","created_at":"2026-06-07T12:55:32.911228+00:00","updated_at":"2026-06-07T12:55:32.911228+00:00","problems":[{"fix":"Use `import { withCacheEffectivePage } from 'next-cache-effective-pages'` in an ES module.","cause":"Incorrect import: using `const { withCacheEffectivePage } = require('next-cache-effective-pages')` in a CommonJS context. The package is ESM-only.","error":"TypeError: withCacheEffectivePage is not a function"},{"fix":"Ensure the callback calls `res.end()` or returns a result that resolves to a valid props object.","cause":"The function passed to `withCacheEffectivePage` did not call `res.end()` or return a value.","error":"Error: getServerSideProps must return a promise. Received undefined."},{"fix":"Add `options: { secondsBeforeRevalidation: <number> }` to the context object.","cause":"Missing `secondsBeforeRevalidation` option in the context.","error":"Warning: 'secondsBeforeRevalidation' is not set; defaulting to 0 (no cache)."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bmstefanski/next-cache-effective-pages#readme","github":"https://github.com/bmstefanski/next-cache-effective-pages","docs":null,"changelog":null,"pypi":null,"npm":"next-cache-effective-pages","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}