Сбой jekyll + работник службы: работник службы не успешно обслуживает манифест start_url - PullRequest
0 голосов
/ 06 июня 2018

не может настроить сервисного работника для сайта проекта с поддержкой jekyll, Lighthouse отклоняет значение start_url и выдает ошибку Unable to fetch start URL via service worker

app-> manifest вывод показывает root /

, также пробовал ./index.html - те же результаты.Есть ли способ пройти аудит?

manifest.json:

{
  "name": "outcast",
  "short_name": "outcast",
  "icons": [
    {
      "src": "/assets/images/splsh192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "/assets/images/splsh512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],
  "lang": "en-US",
  "display": "standalone",
  "background_color": "#131313",
  "theme_color": "#f62e1a",
  "start_url": "/",
  "serviceworker": {
   "src": "sw.js",
   "scope": "/",
   "update_via_cache": "none"
 }
}

sw.js

Ответы [ 2 ]

0 голосов
/ 11 января 2019

Вы можете попробовать это так.У меня была похожая проблема:

self.addEventListener("fetch", function(event) {
  event.respondWith(
    fetch(event.request).catch(function(error) {
      console.log(
        "[Service Worker] Network request Failed. Serving content from cache: " +
          error
      );
      //Check to see if you have it in the cache
      //Return response
      //If not in the cache, then return error page
      return caches
        .open(
          "https://your.website"
        )
        .then(function(cache) {
          return cache.match(event.request).then(function(matching) {
            var report =
              !matching || matching.status == 404
                ? Promise.reject("no-match")
                : matching;
            return report;
          });
        });
    })
  );
});
0 голосов
/ 06 июня 2018

замена обработчика fetch в sw.js кодом из официального руководства исправила проблему.все еще отлаживает неопределенный кеш

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }
        return fetch(event.request);
      }
    )
  );
});
...