I would like to know if it is possible to use the ServiceWorker within an OctoberCms theme? Currently I created a file called serviceworker.js, and apparently it is being recognized, the doubt is being on the offline page, after all, how am I going to create a file to work offline within the october theme?
To get clearer, I'm putting below the example of my serviceworker. My question is how do I add the offline page in the serviceworker?
var CACHE_NAME = 'static-v1';
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_NAME).then(function (cache) {
return cache.addAll([
'/',
'../js/main.min.js',
'../css/style.min.css',
]);
})
)
});
self.addEventListener('activate', function activator(event) {
event.waitUntil(
caches.keys().then(function (keys) {
return Promise.all(keys
.filter(function (key) {
return key.indexOf(CACHE_NAME) !== 0;
})
.map(function (key) {
return caches.delete(key);
})
);
})
);
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request).then(function (cachedResponse) {
return cachedResponse || fetch(event.request);
})
);
});