Improve service worker based caching 2

This commit is contained in:
Hans5958 2023-04-01 15:56:52 +07:00
parent 0e21f1aec8
commit 2588bde989
2 changed files with 15 additions and 17 deletions

View file

@ -8,25 +8,25 @@
"description": "The atlas for the r/place event of 2022 hosted on Reddit.",
"icons": [
{
"src": "/_img/pwa/logo-round-192x192.png",
"src": "./_img/pwa/logo-round-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/_img/pwa/logo-maskable-192x192.png",
"src": "./_img/pwa/logo-maskable-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/_img/pwa/logo-round-512x512.png",
"src": "./_img/pwa/logo-round-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/_img/pwa/logo-maskable-512x512.png",
"src": "./_img/pwa/logo-maskable-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
@ -34,17 +34,17 @@
],
"screenshots": [
{
"src": "/_img/pwa/screenshot-1.png",
"src": "./_img/pwa/screenshot-1.png",
"sizes": "750x1334",
"type": "image/png"
},
{
"src": "/_img/pwa/screenshot-2.png",
"src": "./_img/pwa/screenshot-2.png",
"sizes": "1280x800",
"type": "image/png"
},
{
"src": "/_img/pwa/screenshot-3.png",
"src": "./_img/pwa/screenshot-3.png",
"sizes": "750x1334",
"type": "image/png"
}

View file

@ -1,7 +1,5 @@
// This is the "Offline copy of assets" service worker
const QUEUE_NAME = "bgSyncQueue";
importScripts('https://cdn.jsdelivr.net/npm/workbox-sw@6.5.4/build/workbox-sw.js');
self.addEventListener("message", (event) => {
@ -11,14 +9,13 @@ self.addEventListener("message", (event) => {
});
workbox.routing.registerRoute(
({ url }) => !url.pathname.startsWith('/_img/canvas/'),
({ url }) => {!url.pathname.startsWith('/_img/canvas/')},
new workbox.strategies.NetworkFirst({
cacheName: "main",
plugins: [
new workbox.backgroundSync.BackgroundSyncPlugin(
QUEUE_NAME, {
maxRetentionTime: 24 * 60
// Retry for max of 24 Hours (specified in minutes)
"main-queue", {
maxRetentionTime: 24 * 60 // 24 hours (in minutes)
}
)
]
@ -30,10 +27,11 @@ workbox.routing.registerRoute(
new workbox.strategies.CacheFirst({
cacheName: "canvas",
plugins: [
new workbox.expiration.ExpirationPlugin({
maxAgeSeconds: 7 * 24 * 60
// Expire on 7 days (specified in minutes)
})
new workbox.backgroundSync.BackgroundSyncPlugin(
"canvas-queue", {
maxRetentionTime: 4 * 7 * 24 * 60 // 4 weeks (in minutes)
}
)
]
})
);