为什么在开发PWA应用程序时在service-worker.js中出现错误

时间:2019-03-02 12:25:46

标签: javascript django progressive-web-apps

我正在尝试从Django网站开发一个pwa-app。但是出现以下错误:-

Uncaught (in promise) TypeError: Request failed
Promise.then (async)
(anonymous) @ service-worker.js:16

而我的service-worker.js是:-

{% load static %}
var dataCacheName = 'template-pwa';
var cacheName = 'template-pwa';
var filesToCache = [
  '/',
 "./index.html",
 "./{%static "json/manifest.json" %}",
 "./{%static "js" %}",
 "./{%static "js/app.js" %}",
 "./{%static "js/jquery-3.3.1.js" %}",
 "./{%static "js/materialize.js" %}",
 ];

self.addEventListener('install', function(e) {
  console.log('[ServiceWorker] Install');
  e.waitUntil(
    caches.open(cacheName).then(function(cache) {
      console.log('[ServiceWorker] Caching app shell');
  return cache.addAll(filesToCache);
})
 );
});

self.addEventListener('activate', function(e) {
  console.log('[ServiceWorker] Activate');
  e.waitUntil(
    caches.keys().then(function(keyList) {
      return Promise.all(keyList.map(function(key) {
    if (key !== cacheName && key !== dataCacheName) {
      console.log('[ServiceWorker] Removing old cache', key);
      return caches.delete(key);
        }
      }));
    })
 );
  return self.clients.claim();
});

self.addEventListener('fetch', function(e) {
  console.log('[Service Worker] Fetch', e.request.url);
  e.respondWith(
    caches.match(e.request).then(function(response) {
     return response || fetch(e.request);
    })
  );
});

控制台显示服务工作者已注册。根据控制台,错误位于

e.waitUntil

0 个答案:

没有答案