MCPcopy
hub / github.com/DesignRevision/shards-dashboard-react / checkValidServiceWorker

Function checkValidServiceWorker

src/serviceWorker.js:101–127  ·  view source on GitHub ↗
(swUrl, config)

Source from the content-addressed store, hash-verified

99}
100
101function checkValidServiceWorker(swUrl, config) {
102 // Check if the service worker can be found. If it can't reload the page.
103 fetch(swUrl)
104 .then(response => {
105 // Ensure service worker exists, and that we really are getting a JS file.
106 const contentType = response.headers.get('content-type');
107 if (
108 response.status === 404 ||
109 (contentType != null && contentType.indexOf('javascript') === -1)
110 ) {
111 // No service worker found. Probably a different app. Reload the page.
112 navigator.serviceWorker.ready.then(registration => {
113 registration.unregister().then(() => {
114 window.location.reload();
115 });
116 });
117 } else {
118 // Service worker found. Proceed as normal.
119 registerValidSW(swUrl, config);
120 }
121 })
122 .catch(() => {
123 console.log(
124 'No internet connection found. App is running in offline mode.'
125 );
126 });
127}
128
129export function unregister() {
130 if ('serviceWorker' in navigator) {

Callers 1

registerFunction · 0.85

Calls 1

registerValidSWFunction · 0.85

Tested by

no test coverage detected