1
0
Fork 0
forked from forgejo/forgejo

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:
silverwind 2020-05-21 21:15:19 +02:00
parent 460bc32c71
commit 99d9b0f728
No known key found for this signature in database
GPG key ID: 2E62B41C93869443
9 changed files with 73 additions and 112 deletions

View file

@ -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'}),
);