[Module Listing Request]: Blazing fast, parallel-chunked Cloudflare Edge Cache purger for Nuxt 4 and Nitro.
module-request
### Description
# nuxt-cf-purge
[](https://badge.fury.io/js/nuxt-cf-purge)
[](https://opensource.org/licenses/MIT)
Blazing fast, parallel-chunked Cloudflare Edge Cache purger for Nuxt 4 and Nitro.
## Features
- 🚀 **Parallel Execution:** Purges multiple batches concurrently for maximum performance.
- 📦 **Automatic Chunking:** Automatically splits large URL lists into batches of 100 to respect Cloudflare API limits.
- 🧹 **Build-Time Auto Purge:** Automatically reads your build manifest and purges new assets from Cloudflare upon build completion.
- 🏷️ **Cache-Tag Support:** Purge entire categories of content using Cloudflare Cache-Tags (Enterprise/Business).
- 🪄 **Self-Healing Cache:** Automated route-to-cache mapping triggers purges when specific API routes are hit.
- 🛡️ **Type Safe:** Fully typed helpers added directly to the H3 event context.
- 🔧 **Zero Config:** Falls back to standard Cloudflare environment variables out of the box.
- 🧪 **Test-Ready:** Includes a configurable endpoint for local mocking and integration testing.
## Architecture & Stability
This module is built for high-performance production environments and enterprise-grade reliability.
- 💎 **Zero Allocation Runtime:** Core purge functions are initialized once during startup and assigned by reference to the request context. This eliminates per-request memory overhead and Garbage Collection pressure.
- ⚡ **Serverless-First:** Uses Nitro's `event.waitUntil` to ensure background purge tasks are completed on serverless platforms (Cloudflare Workers/Pages) even after the HTTP response is sent.
- 🩺 **Non-Blocking Initialization:** Startup health checks are asynchronous. Your application will boot instantly even if the Cloudflare API is temporarily unreachable.
- 🛡️ **Parallel Execution:** High-concurrency network calls with automatic chunking ensure your cache is cleared as fast as possible while respecting Cloudflare API rate limits.
## ⚠️ Cloudflare Tier Restrictions
Please note that while `purgeCache` (URLs) and `purgeEverything` are available on all Cloudflare plans, certain advanced eviction methods are restricted by Cloudflare's API:
* **`purgeTags`**: Requires a Cloudflare Enterprise plan (or a specialized Pages/Workers configuration).
* **`purgeHosts` & `purgePrefixes`**: Strictly require a Cloudflare Enterprise plan.
If these methods are invoked on an unsupported tier, the module will gracefully log a `400 Bad Request` upstream API error via Nitro's server logger without crashing your application runtime.
## Build-Time Auto Purge
If you enable `autoPurge`, the module hooks into the Nuxt build process (`build:manifest`). It extracts all generated JS, CSS, and static asset paths from the manifest and purges them from Cloudflare immediately.
**Requirements:**
1. `autoPurge: true`
2. `baseURL`: Your production domain (e.g., `https://example.com`). This is needed to construct the absolute URLs required by the Cloudflare API.
```typescript
export default defineNuxtConfig({
cfPurge: {
autoPurge: true,
baseURL: 'https://example.com'
}
})
```
## Build-Time Auto Purge
| Option | Environment Variable | Description |
| --- | --- | --- |
| `zoneId` | `CLOUDFLARE_ZONE_ID` | Your Cloudflare Zone ID. |
| `apiToken` | `CLOUDFLARE_API_TOKEN` | A Cloudflare API Token with `Zone.Cache Purge` permissions. |
| `autoPurge` | - | Enable automatic purging on build completion (default: `false`). |
| `baseURL` | `CF_PURGE_BASE_URL` | Your production domain (required for `autoPurge` and `invalidations`). |
| `checkHealth` | - | Verify API token validity during Nitro startup (default: `false`). |
| `invalidations` | - | Array of rules for automated route-triggered purges. |
| `endpoint` | - | Custom API endpoint (ignored in production; used for testing). |
## Error Handling
If a purge fails, the module logs the specific error payload from the Cloudflare API to `consola.error`, helping you diagnose issues like invalid tokens or malformed URLs immediately.
## License
MIT
### Repository
https://github.com/daliborgogic/nuxt-cf-purge/
### npm
https://www.npmjs.com/package/nuxt-cf-purge
### Nuxt Compatibility
Nuxt 4
0 条评论