8356
Wx
www-xonecas-io / files
www-xonecas-io / tickets / 1026-browsers-keep-a-stale-site-css-after-a-rebuild.md
2.4 KB
1--- 2id: 1026 3title: Browsers keep a stale site.css after a rebuild 4type: bug 5status: done 6priority: p2 7area: site 8created: 2026-11-08T04:16:55Z 9updated: 2026-11-08T20:16:21Z 10source: agent 11moves: 2026-11-08T05:07:40Z inbox doing drag; 2026-11-08T05:23:59Z doing review agent; 2026-11-08T20:16:21Z review done drag 12--- 13 14After 'make build' changed site.css, agent-browser kept using the old one on reload: the 1020 slider rendered unstyled until I re-fetched /site.css with cache: 'reload'. Pages link a fixed /site.css, and the dev server sends Last-Modified with no Cache-Control, so browsers cache it heuristically. The same will hit visitors after a deploy. 15 16Seen: once, in the VM's agent-browser on 192.168.122.10:8080. Not checked: other static files (projects.js, egg.js), and how Caddy would send them. 17 18## Notes 19 20- 2026-11-08 05:23Z (agent): Fixed: every page links its assets with a content hash, e.g. /site.css?v=274e0b6425, /egg.js?v=88ac0c5d7a. When a rebuild changes a file, its address changes, so a browser can't use a stale cached copy. This covers site.css, egg.js, pager.js, projects.js and logo.svg (both the favicon and the header image). 21 22 How: 23 - New internal/site/assets.go. writeAssets copies the static files, runs Tailwind and hashes the results (sha256, first 10 hex), and the template func 'asset' adds the ?v=. copyStatic and the Tailwind step moved out of build.go to the start of Build, so the hashes exist before any page renders. 24 - The asset versions are now part of public/.stamp. Otherwise commit pages, which are skipped when the build stamp hasn't changed, would keep linking an old version. 25 26 The cost: a rebuild that changes CSS or JS re-renders all 2,830 commit pages, about 65s. A rebuild with no changes stays at about 7s. Any template or Go change already did a full re-render, and most CSS changes come with a template change. 27 28 Checked: 29 - go vet and go test pass. TestBuild now checks that the home page links egg.js with a version. 30 - In agent-browser I loaded /, added a rule to assets/site.css (dt colour rgb(1,2,3)), ran make build and did a plain reload with no cache tricks. The new colour applied. I reverted the CSS and rebuilt, and a plain reload shows the old colour again. 31 32 Not checked: the HTML pages themselves can still be cached heuristically by browsers, since the dev server sends no Cache-Control. Caddy wasn't checked either.