A replaced avatar keeps its old AVIF variant on the live site because the file name does not change
Symptom#
After a deploy with a new avatar picture, the live /static/avatar.jpg is the new file, but /static/avatar-400.avif still shows the old picture. Its response headers show age: 171013 (about 2 days) and s-maxage=31536000 (1 year).
Cause#
The site's own Pages worker sets the header. cache_control_for in worker/src/lib.rs returns public, max-age=2592000, s-maxage=31536000 for each static asset that is not a font, and with_cache_headers writes it over the Cache-Control of the asset response. The generated image variants keep the same file name across builds, so the edge cache keeps the copy from before the deploy for up to 1 year. A comment in the worker names this trade-off.
A Cloudflare Pages _headers file cannot change this. The worker sets Cache-Control after the asset response comes back, so the worker's value wins. There is no cache rule in the Cloudflare dashboard.
Fix#
For the current picture: purge the cached avatar URLs in the Cloudflare dashboard (a custom purge by URL). The new picture then shows at once.
To tell a stale edge copy from a bad deploy, request the same URL with ?v=<timestamp>. The query string misses the cache and shows the deployed file.
The lasting fix landed in commit 9b63fc5 ("fix: serve avatars under content-hashed names"): the build puts the hash of each avatar file's bytes into its name (/static/avatar-400.<hash>.avif), registers the stable-to-hashed mapping with rs.assets.register, and templates resolve it with the asset Tera filter ({{ "/static/avatar-400.avif" | asset }}) or rs.assets.get_path. The worker serves names matching the hashed-avatar rule with public, max-age=31536000, immutable; the rule needs two extra dot-separated parts (the 8+ hex hash segment), so a stable name can never match it. The old stable URLs 404; external link previews re-scrape. Keeping a stable /static/avatar.jpg or .webp was rejected: every reference in the repository uses the hashed names, and a stable copy would be one more separately cached file to maintain.
The user chose hashed names over the other option, a shorter s-maxage (7 days) in the worker for files with a stable name. That option is a one-line change, but a new avatar can stay stale for up to 7 days unless you purge. Hashed names give a new URL for each new picture, so it is never stale and needs no purge; the cost is the change to the build and the templates.
Use rs.hash.file + rs.async.rename + rs.assets.register, not rs.assets.write_hashed: write_hashed writes relative to the project root, not dist/, and rs-web exposes no binary file read to feed it image bytes (rs.fs.read and rs.async.read_file are text-only). The build order is before_build hook, then pages(), then rendering, so both register and the asset filter see the manifest.
The _headers attempt (the commit "feat: bust cache", with static/_headers and a copy_file line in config.lua) had no effect and has been removed.
Evidence#
Checked on 2026-10-01 with curl -sI, after the commit "feat: bust cache" was live:
/static/avatar-400.avif:content-length: 16222,age: 180758,cf-cache-status: HIT. This is the old picture./static/avatar-400.avif?v=<number>:content-length: 22264, a differentetag,cf-cache-status: MISS. This is the new picture.- Both responses have
s-maxage=31536000, not the 7 days from_headers. - A local build put
_headersat the root ofdist/. - After the user purged the cache in the Cloudflare dashboard,
/static/avatar-400.avifreturnedcontent-length: 22264withcf-cache-status: MISS, which is the new picture. The header was stills-maxage=31536000. - The user found no rule under Cache Rules in the dashboard. A search of the repository for
max-agethen found the header text inworker/src/lib.rs.
Verified the fix on 2026-10-01: a local build produced dist/static/avatar-400.9c2012864fa187c2.avif and references to the hashed names in dist/index.html (preload, picture srcset, img src/srcset, full-res link, og:image, twitter:image) with no stable avatar name left; flipping one byte of the avatar in a scratch copy changed the hashed names; cargo test -p rs-website-worker passed. Flipping a byte inside the JPEG's EXIF segment changed only the full-res jpg hash, not the variants — the lossy variants decoded to identical pixels, which content hashing reflects correctly.