forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: go-gitea#11092 Fixes: go-gitea#7372
- Loading branch information
1 parent
460bc32
commit 99d9b0f
Showing
9 changed files
with
73 additions
and
112 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {registerRoute} from 'workbox-routing'; | ||
import {StaleWhileRevalidate} from 'workbox-strategies'; | ||
|
||
const cachedDestinations = new Set([ | ||
'manifest', | ||
'script', | ||
'style', | ||
'worker', | ||
]); | ||
|
||
registerRoute( | ||
({request}) => cachedDestinations.has(request.destination), | ||
new StaleWhileRevalidate({cacheName: 'static-cache-v2'}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters