我正在尝试从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