A subclass of the fetch Headers class that simplifies setting Cache-Control and CDN-specific cache headers for modern CDNs. Version 1.3.1 supports Netlify, Vercel, Cloudflare, and Akamai with automatic platform detection. It provides a chainable API with sensible defaults (CDN cache for 1 year, browser revalidation) and methods like `ttl()`, `swr()`, and `immutable()`. Unlike raw header manipulation, it abstracts CDN-specific quirks and promotes best practices like stale-while-revalidate and surrogate keys. Ships TypeScript types. Released as an npm package and JSR module.
npm install cdn-cache-controlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create CacheHeaders with TTL and stale-while-revalidate, and log the resulting headers. Includes type-safe usage.
Remove the second argument to `new CacheHeaders()` or use `setPlatform('netlify')` method.Use `import` or update your bundler to handle ESM. If you cannot use ESM, stick to 0.x.
Explicitly pass an argument to `swr()`, e.g., `.swr(ONE_HOUR)`.
Manually set the CDN via the second constructor argument or the `setPlatform()` method.
Upgrade Node to 18+ or add a polyfill like `node-fetch` and import `Headers` globally.
Run `npm install cdn-cache-control`. If still failing, ensure your tsconfig.json includes `node_modules/@types` or has `skipLibCheck: false`.
Change to `import { CacheHeaders } from 'cdn-cache-control'` or use dynamic `import()`.