Cloudflare Caching Rule Generator
Generate Cloudflare caching headers and rule suggestions for static assets, HTML, APIs, images, fonts, immutable files, and no-cache routes.
Caching Presets
File Location
Where to place your _headers
public/_headersout/_headers- •Next.js server-side redirects in next.config.ts do not work for static export on Cloudflare Pages.
- •Use output: 'export' in your Next.js config.
- •Place _headers in the public directory before building.
- •Cloudflare Pages should deploy the 'out' directory.
/*.html Cache-Control: public, max-age=0, must-revalidate /_next/static/* Cache-Control: public, max-age=31536000, immutable /images/* Cache-Control: public, max-age=86400, stale-while-revalidate=604800 /fonts/* Cache-Control: public, max-age=31536000, immutable /api/* Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate
Quick Summary
Cache-Control headers in your _headers file for HTML, hashed assets (JS/CSS), APIs, and images on Cloudflare Pages.What is this tool?
Cloudflare Pages has default caching behaviors, but they are often not perfectly optimized for your specific framework. The Caching Rule Generator helps you build explicit Cache-Control headers that tell both the visitor's browser and Cloudflare's edge servers exactly how long to keep files.
How to Use This Tool
- Select your framework (Next.js, React, Astro, etc.) to get the right file location.
- Enable caching rules for the file types in your project (HTML, JS/CSS, Fonts, APIs).
- Review the generated
_headersrules. - Copy the content into your
_headersfile in the correct directory.
What This Tool Generates
_headersrules targeting specific URL paths with optimizedCache-Controldirectives.
Best Practices
- Cache hashed files (JS/CSS with random strings in the name) forever using 'immutable'.
- Never cache HTML documents for long, or users will be stuck on old versions of your app.
- Use 'no-store' for any route that returns user-specific or sensitive data (like /api/profile).
Common Mistakes
- Applying 'max-age=31536000, immutable' to '/*' which caches your index.html forever, breaking your site updates.
- Forgetting that setting a header in _headers affects BOTH the browser cache and Cloudflare's edge cache for static Pages.
- Caching Next.js Server Actions or dynamic API routes on static exports.
Security Notes
- Ensure API routes have strict no-cache policies to prevent accidental data leaks where user A sees user B's cached response.
Frequently Asked Questions
How do I cache static assets on Cloudflare Pages?
What Cache-Control should I use for JS and CSS?
Should HTML be cached?
What is immutable caching?
How do I prevent API caching?
How We Keep Your Configs Safe & Valid
Built-in Error Checking
Every file is checked against official rules. We catch missing fields and bad syntax. YAML indentation errors are flagged right away. Kubernetes, Terraform, and Docker specs are all covered. API versions and labels are verified too. You get valid output every time you generate.
100% Private & Local
All tools run in your browser only. Your API keys never leave your machine. We do not use any tracking scripts. No data is sent to any server. Passwords and secrets stay on your device. Crypto operations use the Web Crypto API. Your privacy is fully protected at all times.
Secure Settings by Default
Configs use safe defaults out of the box. Containers run as non-root users. Root filesystems are set to read-only. Dangerous Linux capabilities are dropped. Network policies limit pod-to-pod traffic. TLS 1.3 is enabled for web servers. Security headers are added where needed.
Ready for CI/CD & Git
Output files are ready for your Git repo. Use them with ArgoCD, Flux, or GitHub Actions. Files use clear formatting and comments. Code review is easy for your team. Indentation and key order are consistent. Test in staging before going to production. Every file is clean and well-structured.
Infrastructure as Code
Store configs in Git alongside your code. Terraform modules include typed variables. Backend configs support remote state locking. Outputs work across multiple modules. Ansible playbooks use clear task steps. Chef and Puppet configs are also supported. Every file works with version control tools.
Monitoring & Tracing
Set up Prometheus with auto-discovery rules. Create Grafana dashboards with template variables. Add alerting rules with severity labels. Use OpenTelemetry for trace collection. Forward logs to Loki or Elasticsearch. Connect to Jaeger or Tempo for tracing. Monitor metrics, logs, and traces together.
Container & Docker Safety
Dockerfiles use multi-stage builds for small images. Base images are pinned to exact versions. Dev files are excluded from final images. Health checks are added for orchestrator use. Containers switch to non-root users. Docker Compose uses named volumes and networks. Resource limits are set in deploy configs.
Multiple Output Formats
Export as YAML, JSON, HCL, or TOML. Kubernetes uses YAML with proper separators. Terraform uses HCL with correct escaping. JSON output has consistent indentation. Copy to clipboard with one click. Preview output with syntax highlighting. Line numbers help you review quickly.