fix for SR
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user