Javascript ServiceWorker脚本评估失败

Javascript ServiceWorker脚本评估失败,javascript,progressive-web-apps,service-worker,service-worker-config,Javascript,Progressive Web Apps,Service Worker,Service Worker Config,我已经添加了谷歌代码到我的服务人员,但它给我在谷歌控制台错误 谷歌控制台中的错误: pwaupdate:176未捕获(承诺中)类型错误:无法使用脚本('/pwabuilder sw.js')为作用域('')注册ServiceWorker:ServiceWorker脚本评估失败 我的服务人员: const CACHE = "pwabuilder-offline-page"; const offlineFallbackPage = "/offline.html"; // Install stag

我已经添加了谷歌代码到我的服务人员,但它给我在谷歌控制台错误

谷歌控制台中的错误:

pwaupdate:176未捕获(承诺中)类型错误:无法使用脚本('/pwabuilder sw.js')为作用域('')注册ServiceWorker:ServiceWorker脚本评估失败

我的服务人员:

const CACHE = "pwabuilder-offline-page";

const offlineFallbackPage = "/offline.html";

// Install stage sets up the offline page in the cache and opens a new cache
self.addEventListener("install", function (event) {
  console.log("[PWA Builder] Install Event processing");

  event.waitUntil(
    http://caches.open(CACHE).then(function (cache) {
      console.log("[PWA Builder] Cached offline page during install");

      if (offlineFallbackPage === "offline.html") {
        return cache.add(new Response("TODO: Update the value of the offlineFallbackPage constant in the serviceworker."));
      }

      return cache.add(offlineFallbackPage);
    })
  );
});

//https://developers.google.com/web/updates/2017/02/navigation-preload
//Acelerar al trabajador de servicio con precargas de navegación
self.addEventListener('fetch', event => {
  event.respondWith(async function() {
    // Respond from the cache if we can
    const cachedResponse = await caches.match(event.request);
    if (cachedResponse) return cachedResponse;

    // Else, use the preloaded response, if it's there
    const response = await event.preloadResponse;
    if (response) return response;

    // Else try the network.
    return fetch(event.request);
  }());
});

function fromCache(request) {
  // Check to see if you have it in the cache
  // Return response
  // If not in the cache, then return the offline page
  return http://caches.open(CACHE).then(function (cache) {
    return cache.match(request).then(function (matching) {
      if (!matching || matching.status === 404) {
        // The following validates that the request was for a navigation to a new document
        if (request.destination !== "document" || request.mode !== "navigate") {
          return Promise.reject("no-match");
        }

        return cache.match(offlineFallbackPage);
      }

      return matching;
    });
  });
}

function updateCache(request, response) {
  return http://caches.open(CACHE).then(function (cache) {
    return cache.put(request, response);
  });
}
这是一个简单的bug=)

该错误意味着:脚本文件中存在问题,它不是有效的JavaScript

我很确定这条线就是罪魁祸首。这是无效的代码:

  return http://caches.open(CACHE).then(function (cache) {
这是一个简单的bug=)

该错误意味着:脚本文件中存在问题,它不是有效的JavaScript

我很确定这条线就是罪魁祸首。这是无效的代码:

  return http://caches.open(CACHE).then(function (cache) {