chore(sw): bump cache version to v9 to purge stale HTML fragments

Stale cached HTML fragments referenced old asset hashes (e.g. 404 on
canvas-PlYnCtxh.js while server has canvas-R4rXE5Sc.js) after frequent
rebuilds. Bumping CACHE_VERSION and the SW registration query string
forces the new SW to install and purge all old versioned caches on
activate.
This commit is contained in:
Jeff Emmett 2026-04-16 16:11:29 -04:00
parent e3f322e7ff
commit 3d11acd48b
2 changed files with 4 additions and 4 deletions

View File

@ -369,7 +369,7 @@ export function renderShell(opts: ShellOptions): string {
// Service worker registration + update detection // Service worker registration + update detection
if ("serviceWorker" in navigator && location.hostname !== "localhost") { if ("serviceWorker" in navigator && location.hostname !== "localhost") {
navigator.serviceWorker.register("/sw.js?v=8").then((reg) => { navigator.serviceWorker.register("/sw.js?v=9").then((reg) => {
function showUpdateBanner() { function showUpdateBanner() {
if (!isStandalone) return; // Only show update prompt in installed PWA if (!isStandalone) return; // Only show update prompt in installed PWA
if (sessionStorage.getItem('rspace_update_dismissed')) return; // dismissed this session if (sessionStorage.getItem('rspace_update_dismissed')) return; // dismissed this session
@ -2304,7 +2304,7 @@ export function renderModuleLanding(opts: ModuleLandingOptions): string {
<script type="module"> <script type="module">
import '/shell.js'; import '/shell.js';
if ("serviceWorker" in navigator && location.hostname !== "localhost") { if ("serviceWorker" in navigator && location.hostname !== "localhost") {
navigator.serviceWorker.register("/sw.js?v=8").catch(() => {}); navigator.serviceWorker.register("/sw.js?v=9").catch(() => {});
} }
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON}); document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
try { try {
@ -2644,7 +2644,7 @@ export function renderSubPageInfo(opts: SubPageInfoOptions): string {
<script type="module"> <script type="module">
import '/shell.js'; import '/shell.js';
if ("serviceWorker" in navigator && location.hostname !== "localhost") { if ("serviceWorker" in navigator && location.hostname !== "localhost") {
navigator.serviceWorker.register("/sw.js?v=8").catch(() => {}); navigator.serviceWorker.register("/sw.js?v=9").catch(() => {});
} }
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON}); document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
try { try {

View File

@ -1,7 +1,7 @@
/// <reference lib="webworker" /> /// <reference lib="webworker" />
declare const self: ServiceWorkerGlobalScope; declare const self: ServiceWorkerGlobalScope;
const CACHE_VERSION = "rspace-v8"; const CACHE_VERSION = "rspace-v9";
const STATIC_CACHE = `${CACHE_VERSION}-static`; const STATIC_CACHE = `${CACHE_VERSION}-static`;
const HTML_CACHE = `${CACHE_VERSION}-html`; const HTML_CACHE = `${CACHE_VERSION}-html`;
const API_CACHE = `${CACHE_VERSION}-api`; const API_CACHE = `${CACHE_VERSION}-api`;