tangled
alpha
login
or
join now
bunware.org
/
pin.to.it
6
fork
atom
Scrapboard.org client
6
fork
atom
overview
issues
pulls
pipelines
fix: preload images instead
bunware.org
7 months ago
dcd3fe63
6dccf930
+1
-71
4 changed files
expand all
collapse all
unified
split
public
sw.js
src
app
layout.tsx
components
Feed.tsx
ServiceWorkerRegistration.tsx
-44
public/sw.js
···
1
-
const CACHE_NAME = "scribble-image-cache-v1";
2
-
3
-
self.addEventListener("install", (event) => {
4
-
self.skipWaiting();
5
-
});
6
-
7
-
self.addEventListener("activate", (event) => {
8
-
event.waitUntil(
9
-
caches.keys().then((cacheNames) => {
10
-
return Promise.all(
11
-
cacheNames.map((cacheName) => {
12
-
if (cacheName !== CACHE_NAME) {
13
-
return caches.delete(cacheName);
14
-
}
15
-
})
16
-
);
17
-
})
18
-
);
19
-
});
20
-
21
-
self.addEventListener("fetch", (event) => {
22
-
// Only cache image requests
23
-
if (event.request.destination === "image") {
24
-
event.respondWith(
25
-
caches.open(CACHE_NAME).then((cache) => {
26
-
return cache.match(event.request).then((cachedResponse) => {
27
-
// Return cached response if found
28
-
if (cachedResponse) {
29
-
return cachedResponse;
30
-
}
31
-
32
-
// Otherwise fetch from network and cache
33
-
return fetch(event.request).then((networkResponse) => {
34
-
// Clone the response before using it
35
-
const responseToCache = networkResponse.clone();
36
-
37
-
cache.put(event.request, responseToCache);
38
-
return networkResponse;
39
-
});
40
-
});
41
-
})
42
-
);
43
-
}
44
-
});
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-2
src/app/layout.tsx
···
7
import { ProfileProvider } from "@/lib/useProfile";
8
import { Toaster } from "sonner";
9
import { BoardsProvider } from "@/lib/hooks/useBoards";
10
-
import { ServiceWorkerRegistration } from "@/components/ServiceWorkerRegistration";
11
12
const geistSans = Geist({
13
variable: "--font-geist-sans",
···
39
<AuthProvider>
40
<ProfileProvider>
41
<BoardsProvider>
42
-
<ServiceWorkerRegistration />
43
<div className="min-h-screen flex flex-col">
44
<Navbar />
45
<main className="flex-1 py-6">{children}</main>
···
7
import { ProfileProvider } from "@/lib/useProfile";
8
import { Toaster } from "sonner";
9
import { BoardsProvider } from "@/lib/hooks/useBoards";
0
10
11
const geistSans = Geist({
12
variable: "--font-geist-sans",
···
38
<AuthProvider>
39
<ProfileProvider>
40
<BoardsProvider>
0
41
<div className="min-h-screen flex flex-col">
42
<Navbar />
43
<main className="flex-1 py-6">{children}</main>
+1
src/components/Feed.tsx
···
140
width={image.aspectRatio?.width ?? 400}
141
height={image.aspectRatio?.height ?? 400}
142
className="object-contain max-w-full max-h-full rounded-lg"
0
143
/>
144
</div>
145
···
140
width={image.aspectRatio?.width ?? 400}
141
height={image.aspectRatio?.height ?? 400}
142
className="object-contain max-w-full max-h-full rounded-lg"
143
+
priority
144
/>
145
</div>
146
-25
src/components/ServiceWorkerRegistration.tsx
···
1
-
"use client";
2
-
3
-
import { useEffect } from "react";
4
-
5
-
export function ServiceWorkerRegistration() {
6
-
useEffect(() => {
7
-
if ("serviceWorker" in navigator && process.env.NODE_ENV === "production") {
8
-
window.addEventListener("load", () => {
9
-
navigator.serviceWorker.register("/sw.js").then(
10
-
(registration) => {
11
-
console.log(
12
-
"Service Worker registered with scope:",
13
-
registration.scope
14
-
);
15
-
},
16
-
(error) => {
17
-
console.error("Service Worker registration failed:", error);
18
-
}
19
-
);
20
-
});
21
-
}
22
-
}, []);
23
-
24
-
return null; // This component doesn't render anything
25
-
}
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0