WEB-23Required
Keep the previous build's assets
After a deploy, keep the hashed files of the last three deploys and of the last 7 days, whichever keeps more. Pages cached before the deploy still find their scripts.
How to do it
Copy the old build's hashed asset folder into the new one without overwriting. Use cp -r --update=none on GNU coreutils 9.3 or later, or cp -rn on macOS and BSD. Delete a hashed file only when no build among the last three deploys produced it and it is over 7 days old. Tabs stay open for days, and HTML may be cached for its max-age plus stale-while-revalidate. See also recover when a new release replaces the old files.
Examples
Shell example
# before the swap: carry old hashed files into the new build, never overwrite
cp -r --update=none /srv/site/live/assets/. /srv/site/next/assets/
How to check
A deploy test loads a page, deploys a build with new hashes, then requests the old page's script and stylesheet addresses. Each answers 200.
Sources
Related rules
- TST-47 Keep the previous release's manifest in Testing
- APP-53 Recover when a new release replaces the old files in Web app interface
- WEB-42 Cache files for a year and pages briefly in Website
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/site-architecture/keep-the-previous-build-s-assets">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.