Prompt

How do I set up a CDN for both static and dynamic content?

Technology / CDN & Edge Infrastructure1 observationLast seen Oct 12, 2026

Latest observation

Oct 12, 2026OpenAI APIWeb search: off

A CDN can help with both static and dynamic content, but they’re handled a bit differently:

  • Static content (images, CSS, JS, fonts, downloads) is ideal for CDN caching.
  • Dynamic content (personalized pages, API responses, logged-in data) usually isn’t cached heavily, but can still benefit from CDN features like edge routing, TLS termination, DDoS protection, and selective/short-lived caching.

1) Start by classifying your content

Separate your app into:

Static assets

Examples:

  • /assets/*
  • /images/*
  • /css/*
  • /js/*
  • /fonts/*

These should be served from the CDN with long cache lifetimes.

Dynamic content

Examples:

  • /api/*
  • /account/*
  • /checkout/*
  • personalized HTML

These usually need:

  • no cache, or
  • very short cache with careful variation rules, or
  • edge compute / origin shielding / response caching for safe endpoints

2) Put the CDN in front of your origin

Typical setup:

Users → CDN → Origin server / app server / storage bucket

Your origin could be:

  • web server (Nginx/Apache)
  • app server (Node/Python/Ruby/etc.)
  • object storage (S3, GCS, Azure Blob) for static content
  • load balancer in front of multiple app instances

You’ll configure the CDN to fetch from your origin when it misses cache.


3) Configure static content caching

For static files:

Use long cache headers

At origin, send headers like:

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

This tells browsers/CDNs to cache aggressively.

Use fingerprinted filenames

Example:

  • app.8f3a1c.js
  • styles.91bdc2.css

Then you can safely cache for a year because changes create new filenames.

CDN rules

Set CDN behavior to:

  • cache everything under static paths
  • respect origin cache headers, or override with strong caching
  • compress assets (Brotli/Gzip)
  • enable HTTP/2 or HTTP/3

4) Handle dynamic content carefully

For dynamic pages and APIs, you usually have three options:

A. Don’t cache

Use:

Cache-Control: no-store

Best for:

  • logged-in pages
  • personal data
  • checkout/cart
  • sensitive APIs

B. Short TTL caching

For content that changes often but can be stale briefly:

Cache-Control: public, max-age=30, s-maxage=60
  • max-age = browser cache
  • s-maxage = shared cache/CDN cache

Good for:

  • product listings
  • homepages
  • news feeds
  • rate-limited APIs

C. Cache at the edge with variation

Cache based on:

  • country/region
  • device type
  • language
  • query string
  • selected cookies

Be careful: varying by cookie or authorization header can destroy cache hit rates and can leak content if misconfigured.


5) Use cache rules by path

Most CDNs let you create rules like:

Static

  • Path matches /static/*, /assets/*, /images/*
  • Cache TTL: 1 year
  • Ignore query strings or normalize them if appropriate

Dynamic API

  • Path matches /api/*
  • Cache TTL: 0 or very short
  • Bypass cache when Authorization header is present

HTML pages

  • Cache only public pages
  • Bypass authenticated sessions
  • Possibly use edge caching for anonymous users

6) Make sure origin sends the right headers

At your origin, configure headers per content type.

Static file example

Cache-Control: public, max-age=31536000, immutable
Content-Encoding: br

Public dynamic content example

Cache-Control: public, max-age=30, s-maxage=300

Private content example

Cache-Control: private, no-store

7) Purge/invalidate when content changes

For static assets:

  • best practice is fingerprinted filenames, so you rarely purge
  • if needed, purge by URL or path

For dynamic cached content:

  • use short TTLs
  • purge on publish/update events if your CDN supports it

8) Protect dynamic endpoints

Even if not cached, the CDN can still help dynamic content by:

  • absorbing DDoS traffic
  • terminating TLS
  • rate limiting
  • bot filtering
  • origin shielding
  • load balancing across regions

9) Common gotchas

  • Caching personalized pages accidentally
    • Don’t cache responses with user-specific data unless carefully separated.
  • Ignoring cookies/authorization
    • Cache rules must bypass or vary correctly.
  • Cache busting with query strings
    • Decide whether query strings should be part of the cache key.
  • Serving stale content too long
    • Use sensible TTLs and purge workflows.
  • Origin cache headers overridden unintentionally
    • Know whether your CDN respects origin headers or has its own rules.

10) Example practical setup

A common pattern:

Static

  • Store assets in object storage or on your origin
  • Serve through CDN
  • Fingerprint filenames
  • Cache for 1 year

Dynamic

  • Serve HTML/API from app servers behind CDN
  • Do not cache authenticated responses
  • Cache public pages for 30–300 seconds where safe
  • Use edge protections and origin shielding

11) A simple decision table

Content typeCDN cache?Typical TTL
JS/CSS/images/fontsYes1 year
Versioned downloadsYes1 year
Public HTMLSometimes30s–5m
Public APISometimes10s–5m
Logged-in pagesUsually no0
Checkout/account dataNo0

If you tell me which CDN you’re using (Cloudflare, Fastly, Akamai, AWS CloudFront, Azure CDN, etc.) and what stack your app runs on, I can give you a concrete configuration example.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation 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.