HTTP Caching Best Practices

HTTP Caching Best Practices

Lays out opinionated HTTP caching rules for web developers: Cache-Control choices, fingerprinted assets, validators, CDN lifetimes and what never to cache.

HTTP Caching taste of a web developer who wants fast pages without stale surprises

  • Decide the caching policy for every response on purpose; a missing Cache-Control header lets browsers and proxies guess. Confidence: 0.90
  • Serve fingerprinted static assets with Cache-Control: public, max-age=31536000, immutable. Confidence: 0.95
  • Put a content hash in asset file names instead of using query strings like ?v=2 for cache busting. Confidence: 0.85
  • Send HTML documents with no-cache or a very short max-age so new deploys show up right away. Confidence: 0.85
  • Use private, no-store for responses with personal or sensitive data, and never let a shared cache hold them. Confidence: 0.95
  • Use s-maxage to give the CDN a different lifetime than the browser when the CDN can be purged and the browser cannot. Confidence: 0.80
  • Add stale-while-revalidate for content that can be a few seconds old, so users rarely wait for the origin. Confidence: 0.80
  • Use stale-if-error so the CDN keeps serving the last good copy when the origin is down. Confidence: 0.70
  • Send strong ETag or Last-Modified validators so revalidation returns a cheap 304 Not Modified. Confidence: 0.80
  • Keep the Vary header minimal; varying on User-Agent or Cookie quietly destroys the CDN hit rate. Confidence: 0.85
  • Never cache responses that set cookies at a shared cache. Confidence: 0.90
  • Purge the CDN by tag or surrogate key after content changes instead of purging everything. Confidence: 0.75
  • Cache API GET responses only when the data is truly shared, and say so explicitly in the response headers. Confidence: 0.80
  • Do not cache error responses for long; a cached 500 or 404 can outlive the real problem. Confidence: 0.80
  • Rely on HTTP caching headers instead of a service worker unless the app truly needs offline support. Confidence: 0.70
  • Watch the CDN cache hit ratio as a key metric, and investigate when it drops after a deploy. Confidence: 0.75
  • Test caching behavior with curl -I against the real CDN, not only in local development. Confidence: 0.80
  • Document the cache rules per route in one place so nobody has to read headers in the browser to learn them. Confidence: 0.65
  • Keep Cache-Control decisions in application code or edge config under version control, not only in a dashboard. Confidence: 0.75
  • Prefer short cache times plus revalidation over long cache times plus emergency purges. Confidence: 0.70

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 11,183 prompts

More by @OpenSourceBuffGuy

See all
Security Headers Configuration prompt image

Security Headers Configuration

Guides an AI coding agent to configure HTTP security headers (CSP, HSTS, X-Frame-Options) for Node, Nginx, Apache and Flask apps, with a testing script and checklist.

agent-skill, application-security, security-review, best-practices, code-generation, web-development, backend, cybersecurity, owasp, nodejs, nginx, python, flask, javascript, bash, for-developers, for-security-professionals, for-devops-engineers, code, checklist, step-by-step-guide, long-form, advanced, frontend, compliance, content-security-policy

Edible City Skyline Diorama prompt image

Edible City Skyline Diorama

Draws a miniature skyline of a chosen country or city built entirely from its local foods, shot as a tilt-shift macro diorama.

image-prompt, miniature, cityscape, food-photography, 3d-render, photorealistic, prompt-weights, negative-prompt, placeholders, template, architecture, macro, soft-lighting, whimsical, unreal-engine, nano-banana

Female fighter faces giant armored warrior in warehouse prompt image

Female fighter faces giant armored warrior in warehouse

Generates a 15-second realistic action video of a woman fighter beating a giant armored opponent in a night warehouse, with timed beats and a fixed look.

video-prompt, action, martial-arts, timed-beats, character-consistency, cinematic, photorealistic, woman, slow-motion, camera-movement, low-angle, dramatic-lighting, seedance, negative-prompt, tracking-shot, handheld, long-form, guardrails, warriors, visual-effects

Reviews

Loading reviews…

Discussion

Loading comments…