fix(nginx): cache hashed assets as immutable, revalidate the rest - #107
Merged
Merged
Conversation
Every asset is served from a ^~ prefix location, and ^~ skips regex locations, so the `location ~* \.(css|js|…)$` long-cache block never ran: hashed _astro/ files went out with only `no-transform` under /knowledge-base/ and no Cache-Control at all under /__wf/knowledge-base/. A map on $request_uri now picks the policy per asset class, applied in both prefix locations (each re-including kb-headers.conf): - _astro/ and the content-addressed _kb-inline/ scripts: public, max-age=31536000, immutable, no-transform - everything else (HTML, style.css, sub-app assets at stable names): no-cache, no-transform — revalidated by ETag, 304 when unchanged Not `always`, so a 404 under _astro/ is never cached for a year. The dead regex location is removed. The Express mirror serves the same map; nginx-config.spec asserts the two agree, container.spec asserts every class against the real image. Closes #66 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #66.
Both prefix locations are
^~, which stops nginx evaluating regex locations, so thelocation ~* \.(css|js|…)$long-cache block never ran in production. Hashed_astro/files went out withCache-Control: no-transformonly (under/knowledge-base/) or no Cache-Control at all (under/__wf/knowledge-base/).Changes
A
map $request_uri $kb_cache_controlpicks the policy per asset class, and both prefix locationsadd_header Cache-Control $kb_cache_control(each re-includingkb-headers.conf):_astro/*(Astro-hashed),{slug}/_kb-inline/<16 hex>.js(content-addressed hoisted scripts)public, max-age=31536000, immutable, no-transformstyle.css, sub-app assetsno-cache, no-transform$request_uri: by the timeadd_headerruns,$urihas lost the prefix to the rewrite.no-cache(revalidate via ETag → 304) rather than unchanged/heuristic. Sub-app assets keep whatever names their generator gave them (docs/style.css), so they have the same stale-for-a-while-after-deploy risk the issue raised forstyle.css.always: a 404 under_astro/must not be cached for a year.no-transformstill rides on every response.Tests
nginx-config.spec.js: both^~locations use the map, withoutalways; no regex location sets a policy; the map and the Express mirror agree on every pattern and value.container.spec.js(real nginx): each class under both prefixes, 404 not immutable, ETag → 304.standalone.spec.js+tests/fragment-server.mjs: the mirror serves the same map.Verification
npm run test:container: 36 passed (fresh image; a stale container on :8099 removed first)playwright.config.ci.js: 23 passednpm test: 396 passed🤖 Generated with Claude Code