forked from github/cinny
Request session info from sw if missing (#2664)
* request session info from sw if missing * fix async session request in fetch * respond fetch synchronously and add early check for non media requests (#2670) * make sure we call respondWith synchronously * simplify isMediaRequest in sw * improve naming in sw * get back baseUrl check into validMediaRequest * pass original request into fetch in sw * extract mediaPath util and performs checks properly --------- Co-authored-by: mmmykhailo <35040944+mmmykhailo@users.noreply.github.com>
This commit is contained in:
@@ -34,17 +34,14 @@ if ('serviceWorker' in navigator) {
|
||||
|
||||
navigator.serviceWorker.register(swUrl).then(sendSessionToSW);
|
||||
navigator.serviceWorker.ready.then(sendSessionToSW);
|
||||
window.addEventListener('load', sendSessionToSW);
|
||||
|
||||
// When returning from background
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') {
|
||||
navigator.serviceWorker.addEventListener('message', (ev) => {
|
||||
const { type } = ev.data ?? {};
|
||||
|
||||
if (type === 'requestSession') {
|
||||
sendSessionToSW();
|
||||
}
|
||||
});
|
||||
|
||||
// When restored from bfcache (important on iOS)
|
||||
window.addEventListener('pageshow', sendSessionToSW);
|
||||
}
|
||||
|
||||
const mountApp = () => {
|
||||
|
||||
Reference in New Issue
Block a user