I'm using vue-pwa for my site and am currently using the NetworkFirst strategy for an API that I call inside my site. I now want to somehow detect if the response I received from the API was cached by the service worker (in which case I want to know how old that cached response is) or if the request was fetched normally. The goal is to display a warning if the user is viewing potentially out of date content (the response was loaded from cache and is older than a few hours)
Here's my current sw.js
self.addEventListener('message', (e) => {
if (!e.data) {
return
}
switch (e.data) {
case 'skipWaiting':
self.skipWaiting()
break
default:
break
}
})
workbox.core.clientsClaim()
self.__precacheManifest = [].concat(self.__precacheManifest || [])
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerRoute(/^https:\/\/some.api.here.com\//, new workbox.strategies.NetworkFirst(), 'GET');