mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-12 16:39:35 +03:00
feat: new portal selection and favicons
This commit is contained in:
58
public/sw.js
Normal file
58
public/sw.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const options = {"autoRegister":true,"cacheOptions":{"directoryIndex":"/","revision":"K6OlwYBfflew"},"enabled":true,"preCaching":[],"templatePath":null,"workboxVersion":"6.5.3","workboxUrl":"https://storage.googleapis.com/workbox-cdn/releases/6.5.3/workbox-sw.js"}
|
||||
|
||||
importScripts(options.workboxUrl)
|
||||
|
||||
self.addEventListener('install', () => self.skipWaiting())
|
||||
self.addEventListener('activate', () => self.clients.claim())
|
||||
|
||||
const { registerRoute } = workbox.routing
|
||||
const { NetworkFirst, StaleWhileRevalidate, CacheFirst } = workbox.strategies
|
||||
const { CacheableResponsePlugin } = workbox.cacheableResponse
|
||||
const { ExpirationPlugin } = workbox.expiration
|
||||
const { precacheAndRoute } = workbox.precaching
|
||||
|
||||
// Cache page navigations (html) with a Network First strategy
|
||||
registerRoute(
|
||||
({ request }) => {
|
||||
return request.mode === 'navigate'
|
||||
},
|
||||
new NetworkFirst({
|
||||
cacheName: 'pages',
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({ statuses: [200] })
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
// Cache Web Manifest, CSS, JS, and Web Worker requests with a Stale While Revalidate strategy
|
||||
registerRoute(
|
||||
({ request }) =>
|
||||
request.destination === 'manifest' ||
|
||||
request.destination === 'style' ||
|
||||
request.destination === 'script' ||
|
||||
request.destination === 'worker',
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: 'assets',
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({ statuses: [200] })
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
// Cache images with a Cache First strategy
|
||||
registerRoute(
|
||||
({ request }) => request.destination === 'image',
|
||||
new CacheFirst({
|
||||
cacheName: 'images',
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({ statuses: [200] }),
|
||||
// 50 entries max, 30 days max
|
||||
new ExpirationPlugin({ maxEntries: 50, maxAgeSeconds: 60 * 60 * 24 * 30 })
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
// Precaching
|
||||
if (options.preCaching.length) {
|
||||
precacheAndRoute(options.preCaching, options.cacheOptions)
|
||||
}
|
Reference in New Issue
Block a user