Overview
Introduction
Picking the right Cache-Control value per asset type is one of the highest-leverage, easiest-to-get-wrong parts of deploying a static site, cache HTML too aggressively and users get stale pages, cache nothing and you lose the performance win entirely.
This tool generates a Cache-Control rule per asset type you select, each pre-set to the value that reflects how often that type of file actually changes.
What Is Cloudflare Pages Caching Rule Generator?
A caching-rule generator covering five common asset categories: static/immutable JS-CSS bundles, HTML documents, API JSON responses, images, and fonts, each mapped to a recommended Cache-Control value and a matching path pattern.
The output is a Cloudflare Pages _headers snippet, one rule block per selected asset type, with a comment explaining why that value fits that asset type.
How Cloudflare Pages Caching Rule Generator Works
Each asset type is a fixed lookup: static/immutable assets get `public, max-age=31536000, immutable`, HTML gets `public, max-age=0, must-revalidate`, API JSON gets `no-cache`, images get a one-week `max-age=604800`, and fonts get the same year-long immutable value as static assets.
Selecting an asset type adds its rule block (path pattern, Cache-Control header, and an explanatory comment) to the generated output; you can select any combination.
When To Use Cloudflare Pages Caching Rule Generator
Use it when setting up caching for a new static site or Pages project and you're not sure what Cache-Control value fits each part of your build output.
It's also useful as a quick reference when auditing an existing site's caching headers against generally recommended values for each asset type.
Often used alongside Cloudflare Pages _headers File Generator and Cloudflare Pages Security Headers Generator.
Features
Advantages
- Encodes the reasoning (not just the value) for each asset type's recommendation directly as a comment in the output.
- Covers the handful of asset categories that account for most of a typical site's cacheable traffic in one tool.
- Lets you combine any subset of the five categories into a single _headers snippet.
Limitations
- The path patterns are common conventions, not detected from your actual build output, adjust them to match your real folder structure before deploying.
- Doesn't cover more advanced caching strategies like stale-while-revalidate or CDN-specific cache tags, only the standard Cache-Control values for each category.
Examples
Best Practices & Notes
Best Practices
- Only apply the year-long immutable Cache-Control to files whose filename actually changes when their content does (a content hash in the filename); otherwise a real content change won't reach users until the cache expires.
- Keep HTML documents on a short or zero max-age so users always get references to your latest hashed assets.
- Reconsider no-cache versus a short positive max-age for API responses that change infrequently but are read very often, revalidation still costs a round trip.
Developer Notes
Each asset type maps to a fixed { path, cacheControl, note } triple; selecting a type emits a `# note` comment line, the path pattern, and an indented `Cache-Control:` line, matching the same block format the general _headers Generator produces so output from both tools can be freely combined.
Cloudflare Pages Caching Rule Generator Use Cases
- Setting up sensible default caching for a new static site deploy
- Auditing an existing Cloudflare Pages project's Cache-Control headers against common recommendations
- Teaching why HTML and hashed assets need very different caching strategies
Common Mistakes
- Applying a long immutable Cache-Control to a file that doesn't have a content hash in its filename, causing stale content to be served after a real update.
- Forgetting to update the generated path patterns to match where your build actually outputs each asset type.
Tips
- Combine this tool's output with the Cloudflare Pages Security Headers Generator's output in one _headers file, performance and security headers commonly live side by side.