mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-07-27 20:37:45 +00:00
886a5b426f
- Add export const dynamic = "force-dynamic" to routes previously pre-rendered as static (rate-probabilities, news, fx, yields, calendar) → fixes empty data on Vercel where static pre-render got HTTP 403 - Add PWA: manifest.json, sw.js, icons, layout meta + apple-touch-icon Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const CACHE = "fxdash-v1";
|
|
const STATIC = ["/", "/manifest.json", "/icons/icon-192.svg", "/icons/icon-512.svg"];
|
|
|
|
self.addEventListener("install", (e) => {
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(STATIC)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (e) => {
|
|
e.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
|
)
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener("fetch", (e) => {
|
|
// Only cache GET requests for same-origin static assets; pass API calls through
|
|
const url = new URL(e.request.url);
|
|
if (e.request.method !== "GET") return;
|
|
if (url.pathname.startsWith("/api/")) return; // always fresh for API
|
|
|
|
e.respondWith(
|
|
caches.match(e.request).then((cached) => {
|
|
const network = fetch(e.request).then((res) => {
|
|
if (res.ok && res.type === "basic") {
|
|
const clone = res.clone();
|
|
caches.open(CACHE).then((c) => c.put(e.request, clone));
|
|
}
|
|
return res;
|
|
});
|
|
return cached || network;
|
|
})
|
|
);
|
|
});
|