Prompt

I'm building a site with lots of JS and CSS; how should I structure CDN caching?

Technology / CDN & Edge Infrastructure2 observationsLast seen Nov 15, 2026

Latest observation

Nov 15, 2026OpenAI APIWeb search: off

For a JS/CSS-heavy site, the best CDN caching strategy is usually:

1) Treat static assets as immutable

Version your files so they can be cached for a very long time.

Examples:

  • /assets/app.3f2c1a.js
  • /assets/styles.a91b8c.css

Or use queryless hashed filenames rather than relying on query strings.

Cache headers for versioned assets

Use something like:

Cache-Control: public, max-age=31536000, immutable

This tells browsers and CDNs:

  • cache for 1 year
  • the file will never change at that URL
  • new content gets a new filename

2) Separate “versioned static” from “HTML”

Keep HTML short-lived, because it references the latest asset versions.

HTML cache headers

Usually:

Cache-Control: no-cache

or

Cache-Control: public, max-age=0, must-revalidate

If you want edge caching for HTML too, use a short TTL plus revalidation, e.g.:

Cache-Control: public, max-age=60, stale-while-revalidate=30

3) Don’t cache user-specific responses publicly

Anything personalized should either:

  • not be cached
  • or vary carefully by auth/session

Examples:

  • dashboards
  • account pages
  • cart contents
  • API responses with user data

Use:

Cache-Control: private, no-store

or at least:

Cache-Control: private, no-cache

depending on whether you want browser-only caching.

4) Use CDN rules by asset type

A good pattern:

JS/CSS/images/fonts

  • long TTL
  • immutable
  • cache at CDN and browser
Cache-Control: public, max-age=31536000, immutable

HTML

  • short TTL or no-cache
  • revalidate frequently
Cache-Control: public, max-age=0, must-revalidate

API JSON

  • depends on whether response is shared or personalized
  • many APIs should be no-store or short TTL

5) Configure CDN to respect origin headers

Prefer to make the origin send correct cache headers and have the CDN honor them. This reduces surprises.

If your CDN supports it, also set:

  • cache key: avoid including cookies/query params unless needed
  • origin shield / tiered caching: improves hit rate
  • compression: enable Brotli/gzip for JS/CSS

6) Avoid cache-busting with random query strings

Bad:

  • /app.js?v=123
  • /app.js?cache=999

Some CDNs and proxies handle query strings inconsistently, and it’s less reliable than filename hashing.

7) Use stale-while-revalidate where appropriate

For assets or HTML that can tolerate brief staleness:

Cache-Control: public, max-age=300, stale-while-revalidate=86400

This lets users get fast responses while the CDN refreshes in the background.

8) Invalidate only when necessary

With hashed filenames, you usually don’t need purges for JS/CSS releases:

  • deploy new files
  • update HTML references
  • old files can stay cached forever

Use CDN purges mainly for:

  • critical HTML fixes
  • broken assets that were published incorrectly
  • content that changes without a URL change

Recommended baseline

For versioned JS/CSS:

Cache-Control: public, max-age=31536000, immutable

For HTML:

Cache-Control: public, max-age=0, must-revalidate

For personalized data:

Cache-Control: private, no-store

If you want, I can give you:

  1. a recommended caching matrix for HTML/JS/CSS/images/API,
  2. Nginx/Apache/CDN config examples, or
  3. a setup tailored to Next.js, React, Vue, or static hosting.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.