From bbccb8a79b76de94ea162e0211d9fd98eeb2a0a6 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 20 Dec 2022 13:21:08 +0800 Subject: [PATCH] Only cache avatars and emojis No point caching all the images for a week Also they take up A LOT of space --- public/sw.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/sw.js b/public/sw.js index 329386cd..b44db070 100644 --- a/public/sw.js +++ b/public/sw.js @@ -5,12 +5,17 @@ import { CacheFirst, StaleWhileRevalidate } from 'workbox-strategies'; const imageRoute = new Route( ({ request, sameOrigin }) => { - return !sameOrigin && request.destination === 'image'; + const isRemote = !sameOrigin; + const isImage = request.destination === 'image'; + const isAvatar = request.url.includes('/avatars/'); + const isEmoji = request.url.includes('/emoji/'); + return isRemote && isImage && (isAvatar || isEmoji); }, new CacheFirst({ cacheName: 'remote-images', plugins: [ new ExpirationPlugin({ + maxEntries: 100, maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days purgeOnQuotaError: true, }),