Progressive web application - service worker not serving start_URL

Played with a progressive web application. I am trying to make a desktop for installing web applications, but I continue to get service worker does not successfully serve the manifest start_urlafter debugging using Lighthouse (Figure below). I am currently hosting my website using azure.

NEW: I checked all my caches, start_url, as well as my service worker, to see that everything is consistent. But it still gives me the same error.

enter image description here

I am not sure if this is my problem start_urlor my service-worker. Below is my code.

manifest.json

  {
   "short_name": "MY EXPERTS",
   "name": "MYEXPERT",
   "icons": [
    {
      "src": "Images/petronas_logo_192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "Images/petronas_logo_192.png",
      "type": "image/png",
      "sizes": "512x512"
    }
 ],

 "background_color": "#FFFFFF",
 "theme_color": "#67BCFF",
 "display": "standalone",
 "start_url": "/Home/Index"
}

AddServiceWorker.js

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').
    then(function (registration) {
        // Registration was successful``
        console.log('ServiceWorker registration successful with scope: ', 
registration.scope);
    }).catch(function (err) {
        // registration failed :(
        console.log('ServiceWorker registration failed: ', err);
    });
}

service-worker.json

 self.addEventListener('install', e => {
 e.waitUntil(
    caches.open('airhorner').then(cache => {
        return cache.addAll([
            '/',
            '/?utm_source=homescreen',
            '/Home/About',
            '/Home/Index',
            '/Home/Contact'
        ])
            .then(() => self.skipWaiting());
    })
  )
});

self.addEventListener('activate', event => {
 event.waitUntil(self.clients.claim());
});

self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request).then(response => {
        return response || fetch(event.request);
    })
  );
});

My browser cache:

enter image description here

+4
source share
1 answer

,

/example/sw.js, fetch , URL /example/ (.. /example/page1/, /example/page2/).

:

  • start_url manifest.json.
  • , , start_url.

, .

+1

Source: https://habr.com/ru/post/1687422/


All Articles