Skip to content

Commit fa3f768

Browse files
committed
Exclude serviceworker registration on localhost
1 parent 48c402a commit fa3f768

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

astro/src/components/Head.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
1010
// Read noindex flag from PUBLIC_ env (Astro will inline this at build time)
1111
const robotsNoindex = import.meta.env.PUBLIC_ROBOTS_NOINDEX === "true";
12+
const isDev = import.meta.env.DEV;
1213
const canonicalUrl = new URL(url.pathname, site);
1314
const metaDescription =
1415
description ??
@@ -29,7 +30,8 @@ const metaDescription =
2930
<slot name="json-ld" />
3031
<slot name="search-scripts" />
3132
<script src="../scripts/header.js"></script>
32-
<script>
33+
{!isDev && (
34+
<script is:inline>
3335
if (navigator.serviceWorker) {
3436
navigator
3537
.serviceWorker
@@ -41,7 +43,7 @@ const metaDescription =
4143
console.log('Service worker registration error:', error);
4244
});
4345
}
44-
</script>
46+
</script>)}
4547
<Font cssVariable="--header" preload />
4648
<Font cssVariable="--body" preload />
4749
</head>

0 commit comments

Comments
 (0)