Repository navigation
Add Cache-Control snippet for static assets to frankenphp images - #4
Merged
Merged
Conversation
Caddy's file_server sends no Cache-Control, so browsers revalidate every asset on every visit and Cloudflare falls back to a short edge TTL and revalidates from every PoP. On the TMG WordPress network that was 42% of origin requests (30k 304s/day on one site). docker-configure now renders 10-cache-headers.caddyfile at boot from two path lists: CADDY_IMMUTABLE_ASSET_PATHS (content-hashed / ?ver= assets, 1 year immutable) and CADDY_MEDIA_PATHS (uploads, 30 days). Nothing is emitted unless a list is set, so the base and dev images are unchanged. The `file` matcher limits the header to files that exist, so 404s are never cached long-term. "*" in a prefix matches one path segment. Dockerfile.wordpress sets defaults for both the Bedrock and stock layouts, including cache-plugin output and Avada's compiled fusion-styles / fusion-scripts directories. Applied to 8.2-8.5; the boot scripts are identical across versions. Verified by rendering the snippet inside a live container and serving it with the hardening snippet on a throwaway listener: versioned assets get the immutable header, media gets 30 days, JSON/PHP/HTML and 404s are untouched, and the no-exec upload handlers still apply. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TW7f1vNou3AhkWSbhwPQuY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docker-configurerenders a second Caddy snippet,10-cache-headers.caddyfile, fromCADDY_IMMUTABLE_ASSET_PATHS(content-hashed /?ver=assets,public, max-age=31536000, immutable) andCADDY_MEDIA_PATHS(uploads,public, max-age=2592000). Nothing is emitted unless a list is set, so the base and dev images behave exactly as before.Dockerfile.wordpresssets defaults covering both Bedrock and stock layouts, cache-plugin output, and Avada's compiledfusion-styles/fusion-scriptsdirs.Why
Caddy's
file_serversends noCache-Control. Browsers revalidate every asset on every visit, and Cloudflare falls back to a short edge TTL and revalidates from every PoP independently. On the TMG network this was 42% of origin requests (about 30k 304s per day on thehairsociety.org alone, from 6,300 distinct Cloudflare edge IPs).Design notes
filematcher inside each named matcher limits the header to files that exist on disk, so a 404 never carries a long TTL.*in a prefix matches a single path segment (multisiteuploads/sites/*/). Dots and+are escaped.Cache-Control: no-cacheon pages is untouched.Test plan
8.4-frankenphp-wordpresscontainer with output redirected to a temp dir; rendered snippet matched expectations.?ver=plugin CSS, wpo-minify bundles and Avada compiles get the immutable header; a media image gets 30 days; JSON under uploads,wp-cron.php, missing files, a PHP file under uploads andreadme.htmlare untouched (the latter two still 404 from the hardening rules).CADDY_*lists set: only00-hardening.caddyfileis written.sh -non all fourdocker-configurecopies;frankenphp validateon the rendered config.cache-controlandcf-cache-statusfrom outside through Cloudflare and watch the origin 304 rate drop.🤖 Generated with Claude Code
https://claude.ai/code/session_01TW7f1vNou3AhkWSbhwPQuY