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

@@ -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);
});
});
}