{"id":13761736,"url":"https://github.com/bmstefanski/next-cache-effective-pages","last_synced_at":"2025-05-12T16:13:31.625Z","repository":{"id":57158366,"uuid":"394644130","full_name":"bmstefanski/next-cache-effective-pages","owner":"bmstefanski","description":"A helper for creating cache-effective server-side-rendered  Next.js pages with minimal effort","archived":false,"fork":false,"pushed_at":"2021-08-11T01:21:05.000Z","size":389,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-03T20:37:02.737Z","etag":null,"topics":["nextjs","nextjs-plugin"],"latest_commit_sha":null,"homepage":"https://next-cache-effective-pages.vercel.app/test.txt?userId=42","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bmstefanski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-10T12:23:59.000Z","updated_at":"2023-03-07T14:20:32.000Z","dependencies_parsed_at":"2022-09-07T01:00:34.591Z","dependency_job_id":null,"html_url":"https://github.com/bmstefanski/next-cache-effective-pages","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmstefanski%2Fnext-cache-effective-pages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmstefanski%2Fnext-cache-effective-pages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmstefanski%2Fnext-cache-effective-pages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmstefanski%2Fnext-cache-effective-pages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmstefanski","download_url":"https://codeload.github.com/bmstefanski/next-cache-effective-pages/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253774581,"owners_count":21962199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs","nextjs-plugin"],"created_at":"2024-08-03T14:00:26.559Z","updated_at":"2025-05-12T16:13:31.594Z","avatar_url":"https://github.com/bmstefanski.png","language":"TypeScript","funding_links":[],"categories":["Nextjs Starter"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eNext.js cache-effective pages\u003c/h1\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/next-cache-effective-pages\"\u003e\u003cimg alt=\"npm version badge\" src=\"https://img.shields.io/npm/v/next-cache-effective-pages\"\u003e\u003c/a\u003e  \n  \u003cimg alt=\"npm bundle size\" src=\"https://img.shields.io/bundlephobia/min/next-cache-effective-pages\"\u003e\n  \u003cimg alt=\"license badge\" src=\"https://img.shields.io/npm/l/next-cache-effective-pages\"\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n## What it does\n\nLet's say you want to re-generate a static file (e.g. public/sitemap.xml) every 15 minutes.\nThe first solution that comes to mind is doing this at build time and it's great and simple, but.... it wouldn't work for mid and big-scale applications (considering that you're rebuilding your app every time there's a change in CMS).\nAnd this is where `next-cache-effective-pages` comes into the picture.  \nIt makes it easier to change your static file into a regeneratable page without you worrying about effective caching and bandwidth attacks.\n\n## Features\n\n- [x] 🙉 Effective caching\n- [x] 🚚 Bandwidth attack proofed\n- [x] 🤠 Simple and flexible API\n- [x] 🐄 No dependencies\n\n## Installation\n\n```\n$ npm i --save next-cache-effective-pages\n\n# or\n\n$ yarn add next-cache-effective-pages\n```\n\n## Example use cases\n\n### Sitemap\n\n```typescript\n// pages/sitemap.xml.js\n\nexport default function Sitemap() {}\n\nexport async function getServerSideProps(ctxt) {\n  return withCacheEffectivePage(async ({ res }) =\u003e {\n    res.setHeader('Content-Type', 'text/xml')\n    res.write(await getAllPosts())\n    res.end()\n  })({ ...ctxt, options: { secondsBeforeRevalidation: 60 * 15 } }) // Re-generate the page every 15 minutes\n}\n```\n\n### Sitemap with pagination\n\n```typescript\n// pages/sitemap.xml.js\n\nexport default function Sitemap() {}\n\nexport async function getServerSideProps(ctxt) {\n  return withCacheEffectivePage(async ({ res, query }) =\u003e {\n    const maxPages = await getMaxPages()\n\n    if (query.page \u003e maxPages) {\n      // redirect to last\n    }\n\n    res.setHeader('Content-Type', 'text/xml')\n    res.write(await getPostsByPage(query.page))\n    res.end()\n  })({ ...ctxt, options: { secondsBeforeRevalidation: 60 * 15, allowedQueryParams: ['page'] } }) // You can whitelist a query parameter\n}\n```\n\n## Options\n\n```typescript\n{\n  secondsBeforeRevalidation?: number; # Self-descriptive\n  allowedQueryParams?: string[]; # These won't be removed from the url while redirecting\n}\n```\n\n## FAQ\n\n### How does it prevent bandwidth attacks?\n\nThe easiest way to attack an app's bandwidth quota is by adding the current timestamp to a request, like so:\n\n```\n$ curl -s -I -X GET \"https://bstefanski.com/sitemap.xml?$(date +%s)\"\n```\n\nIf your site is server-side rendered it will probably miss the cached entry and create a new one.\nThis library prevents from returning an uncached big chunk of data by redirecting to a query-less url (`https://bstefanski.com/sitemap.xml?43534543=0` -\u003e `https://bstefanski.com/sitemap.xml`)\n\n### How are you caching this?\n\nBy setting `Cache-Control` header to `s-maxage=${secondsBeforeRevalidation}, stale-while-revalidate`.\n\n\u003e `stale-while-revalidate` - Indicates the client will accept a stale response, while asynchronously checking in the background for a fresh one.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmstefanski%2Fnext-cache-effective-pages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmstefanski%2Fnext-cache-effective-pages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmstefanski%2Fnext-cache-effective-pages/lists"}