Reputation: 21
When I try to fetch the cached by checking the offline button in dev tools.Its getting no internet connection error and I tried with turning off my wifi its getting cached data.
Upvotes: 0
Views: 487
Reputation: 3200
Offline Button
Offline
check in Chrome inspect tools fully simulates offline network state, so you do not have to turn off your modem, wifi or network adapter while using it.
Observing response source
You can go to Chrome inspect > Network panel and look at the
size
column to check the origin of a response. By just looking at there you will be able to tell a request is served from browser cache, service worker or from network.
The error
If you are getting error because of your
sw.js
while you are offline, it is not a problem. It simply means it could not get service worker from network and it does not have to get it while you are offline anyway. See this answer for a more detailed information about it.
Upvotes: 1
Reputation: 187
I recommend you to install Lighthouse extension for chrome it makes the testing way easier and the reports are quite useful. Are you checking the 'fetch' event for the cache files? And are you sure you have the files cached ?
self.addEventListener('fetch', function(event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
Upvotes: 0