fix(service-worker): fixes service worker issue in init-service-worke… (#3378)

This commit is contained in:
Pavan Kumar Jadda 2023-05-09 17:10:09 -04:00 committed by GitHub
parent 0b4c3649e7
commit 55f996cf48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,13 +3,18 @@
// modules, so it's perfectly fine to serve this code to any browsers // modules, so it's perfectly fine to serve this code to any browsers
// (older browsers will just ignore it) // (older browsers will just ignore it)
// //
import { Workbox } from 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0-beta.1/workbox-window.prod.mjs'; //import { Workbox } from './workbox-window.prod.mjs';
// proper initialization
if( 'function' === typeof importScripts) {
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/6.5.4/workbox-window.prod.mjs'
);
var supportsServiceWorker = 'serviceWorker' in navigator; var supportsServiceWorker = 'serviceWorker' in navigator;
var isNotLocalDevelopment = var isNotLocalDevelopment =
['localhost', '127'].indexOf(location.hostname) === -1; ['localhost', '127'].indexOf(location.hostname) === -1;
if (supportsServiceWorker && isNotLocalDevelopment) { if (supportsServiceWorker && isNotLocalDevelopment) {
const swFileLocation = (window.PUBLIC_URL || '/') + 'sw.js'; const swFileLocation = (window.PUBLIC_URL || '/') + 'sw.js';
const wb = new Workbox(swFileLocation); const wb = new Workbox(swFileLocation);
@ -49,4 +54,6 @@ if (supportsServiceWorker && isNotLocalDevelopment) {
}); });
wb.register(); wb.register();
}
} }