mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 22:00:39 +00:00
Move serviceworker to workbox and fix SSE interference (#11538)
* 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
* rethrow error instead of logging
* await .register
* Revert "rethrow error instead of logging"
This reverts commit 043162ba1f
.
* improve comment
* remove JSRenderer
* add version-based cache invalidation
* refactor
* more refactor
* remove comment
* rename item to fit cache name
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
This commit is contained in:
parent
f6f49700cc
commit
88fe7b5a72
12 changed files with 96 additions and 133 deletions
16
web_src/js/serviceworker.js
Normal file
16
web_src/js/serviceworker.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import {registerRoute} from 'workbox-routing';
|
||||
import {StaleWhileRevalidate} from 'workbox-strategies';
|
||||
|
||||
const cacheName = 'static-cache-v2';
|
||||
|
||||
const cachedDestinations = new Set([
|
||||
'manifest',
|
||||
'script',
|
||||
'style',
|
||||
'worker',
|
||||
]);
|
||||
|
||||
registerRoute(
|
||||
({request}) => cachedDestinations.has(request.destination),
|
||||
new StaleWhileRevalidate({cacheName}),
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue