I hope you can help me with my problem. Currently I build a PWA with a service-worker. It registerd successful, but something is wrong with the installation.
The "caches.open"-promise result in an error: "TypeError: Request failed at ". You can see in Chrome, that the cache is registerd, but empty. I already checked the cache urls thousand times..
Here is my Service-worker Code
var CACHE_NAME = 'surv-cache-1'; var resourcesToCache = [ '/', '/index.html', '/jquery-3.2.1.min.js', '/pouchdb.min-6.4.1.js', '/styles/inline.css', '/scripts/app.js' ]; self.addEventListener('install', function(event) { event.waitUntil( // open the app browser cache caches.open(CACHE_NAME).then(function(cache) { console.log("Install succesfull"); // add all app assets to the cache return cache.addAll(resourcesToCache); }).then(function(out){ console.log(out); }).catch(function(err){ console.log(err); }) ); }); self.addEventListener('fetch', function(event) { event.respondWith( // try to find corresponding response in the cache caches.match(event.request) .then(function(response) { if (response) { // cache hit: return cached result return response; } // not found: fetch resource from the server return fetch(event.request); }).catch(function(err){ console.log(err); }) ); }); And my registration code:
<script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js').then(function(registration) { console.log('Service worker registered:'+registration.scope); }).catch(function(e) { console.log(e); }); }; I didn't get it.. I hope you have an idea :)
EDIT: I think I know now why it don't work. I have a authentication for my domain, so not everybody can access it. While my serviceworker want to caching the data, it get 401 back. So it seems to be a problem with the authentication.
Maybe someone had already the same problem?