issue with notch
This commit is contained in:
@@ -4,14 +4,26 @@
|
||||
- Images: cache-first with bounded eviction
|
||||
*/
|
||||
|
||||
// Bump this value on deploy to invalidate caches.
|
||||
const CACHE_VERSION = "v4";
|
||||
const cacheVersionFromUrl = (() => {
|
||||
try {
|
||||
const v = new URL(self.location.href).searchParams.get("v");
|
||||
if (!v) return null;
|
||||
if (!/^[a-zA-Z0-9._-]{1,64}$/.test(v)) return null;
|
||||
return v;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
const CACHE_VERSION = cacheVersionFromUrl ? `v-${cacheVersionFromUrl}` : "v4";
|
||||
|
||||
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", "/robots.txt"];
|
||||
const assetSuffix = cacheVersionFromUrl ? `?v=${encodeURIComponent(cacheVersionFromUrl)}` : "";
|
||||
|
||||
const SHELL_ASSETS = ["/", `/styles/global.css${assetSuffix}`, "/favicon.png", "/robots.txt"];
|
||||
|
||||
// Cache.addAll() throws if there are any duplicate requests.
|
||||
const SHELL_ASSETS_UNIQUE = Array.from(new Set(SHELL_ASSETS));
|
||||
|
||||
1
site/src/env.d.ts
vendored
1
site/src/env.d.ts
vendored
@@ -5,6 +5,7 @@ interface ImportMetaEnv {
|
||||
readonly PUBLIC_UMAMI_SCRIPT_URL?: string;
|
||||
readonly PUBLIC_UMAMI_WEBSITE_ID?: string;
|
||||
readonly PUBLIC_ENABLE_SW?: string;
|
||||
readonly PUBLIC_ASSET_VERSION?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -13,6 +13,8 @@ const cfg = getPublicConfig();
|
||||
|
||||
const siteUrl = (cfg.siteUrl || "http://localhost:4321").replace(/\/$/, "");
|
||||
const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath : `/${canonicalPath}`}`;
|
||||
|
||||
const assetSuffix = cfg.assetVersion ? `?v=${encodeURIComponent(cfg.assetVersion)}` : "";
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@@ -48,7 +50,7 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
|
||||
rel="stylesheet"
|
||||
/>
|
||||
|
||||
<link rel="stylesheet" href="/styles/global.css" />
|
||||
<link rel="stylesheet" href={`/styles/global.css${assetSuffix}`} />
|
||||
|
||||
<script is:inline>
|
||||
(() => {
|
||||
@@ -117,12 +119,13 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
|
||||
// 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>
|
||||
<script is:inline define:vars={{ assetSuffix }}>
|
||||
if ("serviceWorker" in navigator) {
|
||||
// SW requires HTTPS (or localhost). In prod we expect HTTPS.
|
||||
window.addEventListener("load", () => {
|
||||
const swUrl = "/sw.js" + assetSuffix;
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js", { scope: "/", updateViaCache: "none" })
|
||||
.register(swUrl, { scope: "/", updateViaCache: "none" })
|
||||
.catch((err) => {
|
||||
// Progressive enhancement; keep failures non-fatal.
|
||||
console.warn("Service worker registration failed", err);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
type PublicConfig = {
|
||||
siteUrl?: string;
|
||||
assetVersion?: string;
|
||||
umami?: {
|
||||
scriptUrl: string;
|
||||
websiteId: string;
|
||||
@@ -23,11 +24,13 @@ type IngestConfig = {
|
||||
|
||||
export function getPublicConfig(): PublicConfig {
|
||||
const siteUrl = import.meta.env.PUBLIC_SITE_URL;
|
||||
const assetVersion = import.meta.env.PUBLIC_ASSET_VERSION;
|
||||
const scriptUrl = import.meta.env.PUBLIC_UMAMI_SCRIPT_URL;
|
||||
const websiteId = import.meta.env.PUBLIC_UMAMI_WEBSITE_ID;
|
||||
|
||||
return {
|
||||
siteUrl,
|
||||
assetVersion,
|
||||
umami: scriptUrl && websiteId ? { scriptUrl, websiteId } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user