fix for SR
Some checks failed
ci / site (push) Has been cancelled
publish-image / publish (push) Has been cancelled

This commit is contained in:
2026-02-10 17:54:13 -05:00
parent 5d07e57256
commit 57ad560b01
18 changed files with 389 additions and 110 deletions

View File

@@ -5,13 +5,13 @@
*/
// Bump this value on deploy to invalidate caches.
const CACHE_VERSION = "v2";
const CACHE_VERSION = "v3";
const CACHE_SHELL = `shell-${CACHE_VERSION}`;
const CACHE_PAGES = `pages-${CACHE_VERSION}`;
const CACHE_MEDIA = `media-${CACHE_VERSION}`;
const SHELL_ASSETS = ["/", "/styles/global.css", "/favicon.png", "/favicon.png", "/robots.txt"];
const SHELL_ASSETS = ["/", "/styles/global.css", "/favicon.png", "/robots.txt"];
// Keep media cache bounded so we don't grow indefinitely.
const MAX_MEDIA_ENTRIES = 80;

View File

@@ -57,15 +57,16 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
}
{
// Register SW only in production builds (Astro sets import.meta.env.PROD at build time)
// and only when explicitly enabled by env.
import.meta.env.PROD && import.meta.env.PUBLIC_ENABLE_SW === "true" ? (
// Register SW only in production builds (Astro sets import.meta.env.PROD at build time).
// Allow opting out via PUBLIC_ENABLE_SW="false".
import.meta.env.PROD && import.meta.env.PUBLIC_ENABLE_SW !== "false" ? (
<script is:inline>
if ("serviceWorker" in navigator) {
// SW requires HTTPS (or localhost). In prod we expect HTTPS.
window.addEventListener("load", () => {
navigator.serviceWorker.register("/sw.js", { scope: "/" }).catch(() => {
// noop: SW is progressive enhancement
navigator.serviceWorker.register("/sw.js", { scope: "/" }).catch((err) => {
// Progressive enhancement; keep failures non-fatal.
console.warn("Service worker registration failed", err);
});
});
}