Ashutosh
Ashutosh

Reputation: 1060

A possible issue with Service Worker which prevents website from working offline

I created a new website and added a service worker. It gets installed but refuses to work offline. I am loading all resources from cache explicitly by specifying all the URL's. Could someone explain why is the main request failing?

Requests snapshot

Link: http://ashutoshysingh.com/sw.js

Update 1: I have readded the index.html file in cache.

  1. Error shown in Firefox console:

Failed to load 'https://www.ashutoshysingh.com/'. A ServiceWorker passed a promise to FetchEvent.respondWith() that rejected with 'TypeError: NetworkError when attempting to fetch resource.'.

  1. Error in Chrome console:

The FetchEvent for "https://www.ashutoshysingh.com/" resulted in a network error response: the promise was rejected.

Upvotes: 2

Views: 1896

Answers (1)

Stef Chäser
Stef Chäser

Reputation: 2058

You have to add your appshell (index.html or similar) to the cache as well:

caches.open(staticCacheName).then(function(cache) {
  return cache.addAll([
        '/', or 'index.html',
        'assets/css/styles.css',
        ...,

Upvotes: 0

Related Questions