Skip to content

Commit

Permalink
fix: avoid unnecessary imageProxy work and tune serviceworker caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Aug 11, 2024
1 parent e147c5c commit a4772ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
if (bookmark.image) {
return `${PUBLIC_WORKER_URL}/img/s_260x144/${bookmark.image}`
} else {
return `${PUBLIC_WORKER_URL}/img/s_260x144/https://source.unsplash.com/random/240x144?sig=${bookmark.url}`
return `${PUBLIC_WORKER_URL}/img/_/https://source.unsplash.com/random/260x144?sig=${bookmark.url}`
}
})
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/components/feed-row/FeedRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
if (feedEntry.feedMedia?.[0]?.href) {
return `${PUBLIC_WORKER_URL}/img/s_160x96/${feedEntry.feedMedia?.[0]?.href}`
} else {
return `${PUBLIC_WORKER_URL}/img/s_160x96/https://picsum.photos/seed/${encodeURIComponent(feedEntry.id)}/240/153.webp`
return `${PUBLIC_WORKER_URL}/img/_/https://picsum.photos/seed/${encodeURIComponent(feedEntry.id)}/160/96.webp`
}
})
Expand Down
15 changes: 10 additions & 5 deletions apps/web/src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sw.addEventListener("fetch", (event: FetchEvent) => {
event.respondWith(Response.redirect("./?shared=true"))

event.waitUntil(
(async function () {
(async function() {
const textParam = url.searchParams.get("text")
const urlParam = url.searchParams.get("link")

Expand Down Expand Up @@ -79,7 +79,6 @@ const cacheKeys = {
}

sw.addEventListener("message", (event) => {
console.log("sw.global.message", JSON.stringify(event), event)
if (event.data && event.data.type === "SKIP_WAITING") {
sw.skipWaiting()
}
Expand All @@ -91,18 +90,24 @@ const fontAssetRoute = new Route(
},
new CacheFirst({
cacheName: cacheKeys.fonts,
plugins: [
new ExpirationPlugin({
// Only cache requests for 24hrs
maxAgeSeconds: 24 * 60 * 60,
}),
],
}),
)
const imageAssetRoute = new Route(
({ request, url }) => {
return request.destination === "image" && !url.hostname.includes("logo.clearbit.com")
return request.destination === "image" && !url.hostname.includes("api-dev.briefkastenhq.com")
},
new CacheFirst({
cacheName: cacheKeys.images,
plugins: [
new ExpirationPlugin({
// Only cache requests for a week
maxAgeSeconds: 7 * 24 * 60 * 60,
// Only cache requests for 24hrs
maxAgeSeconds: 24 * 60 * 60,
}),
],
}),
Expand Down

0 comments on commit a4772ef

Please sign in to comment.