Fix service workers
This commit is contained in:
@@ -5,6 +5,11 @@ PUBLIC_SITE_URL=https://example.com
|
||||
PUBLIC_UMAMI_SCRIPT_URL=https://analytics.example.com/script.js
|
||||
PUBLIC_UMAMI_WEBSITE_ID=00000000-0000-0000-0000-000000000000
|
||||
|
||||
# Service worker toggle (public, build-time). Use to enable in prod/staging.
|
||||
# - In `npm run dev`, service workers are not registered regardless.
|
||||
# - In `npm run build`/`preview`, SW is registered only if this is "true".
|
||||
PUBLIC_ENABLE_SW=true
|
||||
|
||||
# Content ingestion configuration (used by scripts)
|
||||
YOUTUBE_CHANNEL_ID=UCxxxxxxxxxxxxxxxxxxxxxx
|
||||
YOUTUBE_API_KEY=
|
||||
|
||||
1
site/src/env.d.ts
vendored
1
site/src/env.d.ts
vendored
@@ -4,6 +4,7 @@ interface ImportMetaEnv {
|
||||
readonly PUBLIC_SITE_URL?: string;
|
||||
readonly PUBLIC_UMAMI_SCRIPT_URL?: string;
|
||||
readonly PUBLIC_UMAMI_WEBSITE_ID?: string;
|
||||
readonly PUBLIC_ENABLE_SW?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -57,8 +57,9 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
|
||||
}
|
||||
|
||||
{
|
||||
// Register SW only in production builds (Astro sets import.meta.env.PROD at build time).
|
||||
import.meta.env.PROD ? (
|
||||
// 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" ? (
|
||||
<script is:inline>
|
||||
{`
|
||||
if ("serviceWorker" in navigator) {
|
||||
|
||||
Reference in New Issue
Block a user