Only cache avatars and emojis

No point caching all the images for a week
Also they take up A LOT of space
This commit is contained in:
Lim Chee Aun 2022-12-20 13:21:08 +08:00
parent 1538400dc0
commit bbccb8a79b

View file

@ -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,
}),