mirror of
https://github.com/go-gitea/gitea
synced 2025-07-04 01:27:20 +00:00
Move serviceworker to workbox and fix SSE interference
Instead of statically hardcoding every frontend asset, this uses a type-based approach to cache all js,css and manifest.json requests. This also fixes the issue that the service worker was interfering with EventSource because it was unconditionally handling all requests which this new implementation doesn't. Fixes: https://github.com/go-gitea/gitea/issues/11092 Fixes: https://github.com/go-gitea/gitea/issues/7372
This commit is contained in:
24
web_src/js/features/serviceworker.js
Normal file
24
web_src/js/features/serviceworker.js
Normal file
@ -0,0 +1,24 @@
|
||||
const {UseServiceWorker, AppSubUrl} = window.config;
|
||||
|
||||
async function unregister() {
|
||||
for (const registration of await navigator.serviceWorker.getRegistrations()) {
|
||||
const serviceWorker = registration.active;
|
||||
if (!serviceWorker) continue;
|
||||
registration.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
export default async function initServiceWorker() {
|
||||
if (!('serviceWorker' in navigator)) return;
|
||||
|
||||
if (UseServiceWorker) {
|
||||
try {
|
||||
navigator.serviceWorker.register(`${AppSubUrl}/serviceworker.js`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await unregister();
|
||||
}
|
||||
} else {
|
||||
await unregister();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user