jekyll + service worker failure:服务工作者未成功提供清单的start_url

时间:2018-06-06 00:01:10

标签: google-chrome-devtools jekyll service-worker workbox lighthouse

无法为jekyll支持的项目网站设置服务工作者,灯塔拒绝start_url值并发出错误Unable to fetch start URL via service worker

app->manifest输出显示了根/

尝试./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 :(得分: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);
      }
    )
  );
});

答案 1 :(得分: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;
          });
        });
    })
  );
});