Mad World #Save_GAZA: Free Palestine  

Search

Cloudflare CDN Caching for a Self-Hosted Site

Cloudflare CDN Caching for a Self-Hosted Site

Cloudflare caches static assets when traffic routes through a proxied DNS record, but eligibility depends on file extension, origin headers, cookies, and request method. HTML and JSON stay uncached by default. You can override defaults with Cache Rules or purge a specific file to fetch a fresh copy from the origin.

Confirm the site's traffic passes through Cloudflare

Cloudflare caches content only when the relevant DNS record is proxied. Open your Cloudflare DNS settings and check that the record for your domain shows an orange cloud icon.

If the icon is gray, click it to enable proxying.

Identify what Cloudflare caches by default

Cloudflare caches resources based on file extension, not MIME type. Common static assets like CSS, JS, images (AVIF, BMP, GIF, ICO, JPG, JPEG, PNG, SVG, SVGZ, WEBP), fonts (EOT, OTF, TTF, WOFF, WOFF2), media files (AVI, FLAC, MID, MIDI, MKV, MP3, MP4, OGG, WEBM), documents (DOC, DOCX, PDF, PPT, PPTX, XLS, XLSX), and archives (7Z, APK, BIN, BZ2, DMG, EXE, GZ, ISO, JAR, RAR, SWF, TAR, TIF, TIFF, ZIP, ZST) are eligible. Cloudflare also caches robots.txt by default.

Even when a file extension qualifies, Cloudflare skips caching if the origin response includes Cache-Control: private, no-store, no-cache, or max-age=0, or if a Set-Cookie header is present. Only GET requests are cached; POST, PUT, and other methods bypass the cache.

When no Cache-Control or Expires header arrives from the origin, Cloudflare applies a default Edge Cache TTL: 120 minutes for 200, 206, and 301 responses; 20 minutes for 302 and 303; and 3 minutes for 404 and 410.

Trace a missing cache entry to headers, cookies, or request method

If an eligible static asset isn't cached, check the origin's Cache-Control and Set-Cookie headers. A response that sets a cookie will bypass the cache even if the file extension qualifies. Confirm the request method is GET; Cloudflare does not cache other methods.

When Origin Cache Control is enabled (the default for Free, Pro, and Business plans), Cloudflare strictly respects Cache-Control directives from the origin. To cache content the origin marks as uncacheable, you must use a Cache Rule with an Edge Cache TTL setting.

Cache HTML or JSON with a Cache Rule

If you need to cache a response that doesn't meet the default criteria, create a Cache Rule. Cache Rules let you specify which paths or query strings to cache and how long to store them, overriding the default behavior and origin headers when configured to do so.

Do not cache responses that include private or authenticated content. The supplied evidence does not establish a safe procedure for verifying that authenticated responses bypass the cache.

Refresh a stale file with a targeted purge

When Cloudflare serves an outdated version of a file, purge the cached copy to force a fresh fetch from the origin. You can purge all cached files at once or purge by URL to clear a specific file.

Enter the full URL of the stale resource (for example, https://example.com/styles/main.css) and submit the purge request. The next request for that URL will reach your origin, and Cloudflare will cache the fresh response according to the applicable headers and rules.

Next step

If you're updating static assets frequently, enable Development Mode before making changes.

Verification status: Supported by official documentation only under the conditions below; not reproduced in a test environment by IGPROD. Checked 2026-10-20.

Conditions:

  • The site’s relevant DNS record must be proxied for its web traffic to pass through Cloudflare.
  • The stated default caching behavior is subject to origin cache headers, Set-Cookie, request method, file extension, and applicable Cache Rules.
  • Cloudflare caches a resource only within the data center serving the request.

Sources:

Yassine

Yassine runs IGPROD and has written about Synology NAS, Docker and self-hosting here since 2022. About IGPROD

Leave a comment

Your email address will not be published. Required fields are marked *

Your experience on this site will be improved by allowing cookies Cookie Policy