|
1 | 1 | <h1 align="center">cdn-cache-control</h1> |
2 | | -<p align="center"> |
| 2 | +<p align="center"> |
3 | 3 | <img alt="cdn-cache-control" src="https://github.com/user-attachments/assets/62464d67-cbd5-48b5-a36d-800678ae22bb" /> |
4 | 4 | </p> |
5 | 5 |
|
6 | | - |
7 | 6 | Easy, opinionated CDN cache header handling. |
8 | 7 |
|
9 | 8 | Modern CDNs allow very fine-grained control over the cache. This is particularly useful for server-side rendering of web content, as it allows you to manually handle the invalidation of content, ensuring it stays fast and fresh. This package provides a subclass of the `Headers` class that makes it easier to set cache control headers for content served through a modern CDN. It provides a simple, chainable API with sensible defaults for common use cases. It works by setting the `Cache-Control` and `CDN-Cache-Control` headers to the appropriate values. If run on a supported platform it will use the more specific header for that CDN. e.g. on Netlify it will use the `Netlify-CDN-Cache-Control` header. |
@@ -33,6 +32,8 @@ The module exports a single class, `CacheHeaders`, which is a subclass of the fe |
33 | 32 |
|
34 | 33 | It can be instantiated with a `HeadersInit` value, which lets you base it on an existing `Headers` object, or an object or array with existing header values. In that case it will default to using existing `s-maxage` directives if present. |
35 | 34 |
|
| 35 | +You can pass a `cdn` value as the second argument to set the CDN cache control header. In some cases this will enable targeted cache header names. e.g. for Netlify it will use the `Netlify-CDN-Cache-Control` header. Currently supported values are `netlify`, `vercel`, `cloudflare` and `akamai`. If you don't pass a value, or pass an unsupported one it will use the generic `CDN-Cache-Control` header. It will also attempt to detect the platform automatically on Vercel and Netlify. |
| 36 | + |
36 | 37 | ### Use cases |
37 | 38 |
|
38 | 39 | If you have content that you want to have the CDN cache until it is manually revalidated or purged with a new deploy, you can use the default values: |
@@ -178,18 +179,34 @@ Number of seconds in one year |
178 | 179 |
|
179 | 180 | ### Methods |
180 | 181 |
|
181 | | -- [tag](#gear-tag) |
182 | | -- [swr](#gear-swr) |
183 | | -- [immutable](#gear-immutable) |
184 | | -- [ttl](#gear-ttl) |
185 | | -- [toObject](#gear-toobject) |
186 | | -- [copyTo](#gear-copyto) |
187 | | -- [getCdnCacheControl](#gear-getcdncachecontrol) |
188 | | -- [setCdnCacheControl](#gear-setcdncachecontrol) |
189 | | -- [getCacheControl](#gear-getcachecontrol) |
190 | | -- [setCacheControl](#gear-setcachecontrol) |
191 | | -- [getCacheTags](#gear-getcachetags) |
192 | | -- [setCacheTags](#gear-setcachetags) |
| 182 | +- [Installation](#installation) |
| 183 | +- [Usage](#usage) |
| 184 | + - [Use cases](#use-cases) |
| 185 | + - [stale-while-revalidate](#stale-while-revalidate) |
| 186 | + - [Immutable content](#immutable-content) |
| 187 | + - [Cache tags](#cache-tags) |
| 188 | + - [Using the generated headers](#using-the-generated-headers) |
| 189 | +- [API](#api) |
| 190 | +- [:wrench: Constants](#wrench-constants) |
| 191 | + - [:gear: ONE\_MINUTE](#gear-one_minute) |
| 192 | + - [:gear: ONE\_HOUR](#gear-one_hour) |
| 193 | + - [:gear: ONE\_DAY](#gear-one_day) |
| 194 | + - [:gear: ONE\_WEEK](#gear-one_week) |
| 195 | + - [:gear: ONE\_YEAR](#gear-one_year) |
| 196 | +- [:factory: CacheHeaders](#factory-cacheheaders) |
| 197 | + - [Methods](#methods) |
| 198 | + - [:gear: tag](#gear-tag) |
| 199 | + - [:gear: swr](#gear-swr) |
| 200 | + - [:gear: immutable](#gear-immutable) |
| 201 | + - [:gear: ttl](#gear-ttl) |
| 202 | + - [:gear: toObject](#gear-toobject) |
| 203 | + - [:gear: copyTo](#gear-copyto) |
| 204 | + - [:gear: getCdnCacheControl](#gear-getcdncachecontrol) |
| 205 | + - [:gear: setCdnCacheControl](#gear-setcdncachecontrol) |
| 206 | + - [:gear: getCacheControl](#gear-getcachecontrol) |
| 207 | + - [:gear: setCacheControl](#gear-setcachecontrol) |
| 208 | + - [:gear: getCacheTags](#gear-getcachetags) |
| 209 | + - [:gear: setCacheTags](#gear-setcachetags) |
193 | 210 |
|
194 | 211 | #### :gear: tag |
195 | 212 |
|
@@ -300,15 +317,3 @@ The parsed content of the cache tags header. |
300 | 317 | | `setCacheTags` | `(tags: string[]) => void` | |
301 | 318 |
|
302 | 319 | <!-- TSDOC_END --> |
303 | | - |
304 | | -``` |
305 | | -
|
306 | | -``` |
307 | | - |
308 | | -``` |
309 | | -
|
310 | | -``` |
311 | | - |
312 | | -``` |
313 | | -
|
314 | | -``` |
|
0 commit comments