mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-03 17:21:46 +03:00
fix: add new service worker (#2971)
This commit is contained in:
parent
2f4ee35561
commit
4d95c17e86
4 changed files with 31 additions and 1 deletions
|
@ -7,7 +7,7 @@ export const pwa: VitePWANuxtOptions = {
|
||||||
disable: /* temporarily test in CI isPreview || */ (isDevelopment && process.env.VITE_DEV_PWA !== 'true'),
|
disable: /* temporarily test in CI isPreview || */ (isDevelopment && process.env.VITE_DEV_PWA !== 'true'),
|
||||||
scope: '/',
|
scope: '/',
|
||||||
srcDir: './service-worker',
|
srcDir: './service-worker',
|
||||||
filename: 'sw.ts',
|
filename: 'elk-sw.ts',
|
||||||
strategies: 'injectManifest',
|
strategies: 'injectManifest',
|
||||||
injectRegister: false,
|
injectRegister: false,
|
||||||
includeManifestIcons: false,
|
includeManifestIcons: false,
|
||||||
|
|
|
@ -202,6 +202,11 @@ export default defineNuxtModule<VitePWANuxtOptions>({
|
||||||
'Cache-Control': 'public, max-age=0, must-revalidate',
|
'Cache-Control': 'public, max-age=0, must-revalidate',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
nitroConfig.routeRules!['/elk-sw.js'] = {
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': 'public, max-age=0, must-revalidate',
|
||||||
|
},
|
||||||
|
}
|
||||||
for (const locale of pwaLocales) {
|
for (const locale of pwaLocales) {
|
||||||
nitroConfig.routeRules![`/manifest-${locale.code}.webmanifest`] = {
|
nitroConfig.routeRules![`/manifest-${locale.code}.webmanifest`] = {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
24
public/sw.js
Normal file
24
public/sw.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// DON'T REMOVE THIS FILE: IT IS THE OLD sw.js
|
||||||
|
self.addEventListener('install', (e) => {
|
||||||
|
self.skipWaiting();
|
||||||
|
});
|
||||||
|
self.addEventListener('activate', (e) => {
|
||||||
|
self.registration.unregister()
|
||||||
|
.then(() => self.clients.matchAll())
|
||||||
|
.then((clients) => {
|
||||||
|
clients.forEach((client) => {
|
||||||
|
if (client instanceof WindowClient)
|
||||||
|
client.navigate(client.url);
|
||||||
|
});
|
||||||
|
return Promise.resolve();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
self.caches.keys().then((cacheNames) => {
|
||||||
|
Promise.all(
|
||||||
|
cacheNames.map((cacheName) => {
|
||||||
|
return self.caches.delete(cacheName);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
|
@ -43,6 +43,7 @@ if (import.meta.env.PROD) {
|
||||||
/^\/emojis\//,
|
/^\/emojis\//,
|
||||||
// exclude sw: if the user navigates to it, fallback to index.html
|
// exclude sw: if the user navigates to it, fallback to index.html
|
||||||
/^\/sw.js$/,
|
/^\/sw.js$/,
|
||||||
|
/^\/elk-sw.js$/,
|
||||||
// exclude webmanifest: has its own cache
|
// exclude webmanifest: has its own cache
|
||||||
/^\/manifest-(.*).webmanifest$/,
|
/^\/manifest-(.*).webmanifest$/,
|
||||||
]
|
]
|
Loading…
Reference in a new issue