// Swap changed assets in place. Injected into every page by debug builds only. // see `assets::reload_script`. new EventSource("/assets/_reload").onmessage = (event) => { const bust = (url) => { const parsed = new URL(url, location.href); parsed.searchParams.set("v", Date.now()); return parsed.href; }; const stylesheets = () => { for (const link of document.querySelectorAll('link[rel="stylesheet"]')) { link.href = bust(link.href); } }; const path = event.data; if (path.endsWith(".css")) { stylesheets(); } else if (/\.(png|jpe?g|gif|svg|webp|avif|ico)$/i.test(path)) { for (const img of document.querySelectorAll("img")) { img.src = bust(img.src); } // Stylesheets may reference the image, and those URLs don't change. stylesheets(); } else { // Scripts and anything unrecognized can't be swapped safely. location.reload(); } };