jekyll + 服务工作线程失败:服务工作线程未成功提供清单的 start_url

问题描述 投票:0回答:2

我无法为 Jekyll 支持的项目站点设置 Service Worker - Lighthouse 拒绝

start_url
值并给出错误
Unable to fetch start URL via service worker

app->manifest输出显示根

/

也尝试过

./index.html
- 结果相同。有办法通过审核吗?


清单.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

google-chrome-devtools jekyll progressive-web-apps service-worker lighthouse
2个回答
2
投票

用官方指南中的代码替换

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);
      }
    )
  );
});

0
投票

你可以这样尝试。我也遇到过类似的问题:

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;
          });
        });
    })
  );
});
© www.soinside.com 2019 - 2024. All rights reserved.