I am working on a progressive web app using service worker every thing is working perfectly. Now I want to hide some content on my pages if pages are served from cache so I need to add class "offline" to the body.
Please tell me how can I add document.body.classList.add("offline"); in the below code.
//Fetch from network failed
var fallback = function() {
if (event.request.headers.get('Accept').indexOf('text/html') != -1) {
return caches.match(event.request).then(function (response) {
// need to return the response and add class "offline" to the body here
return response || caches.match('offline-page.html');
})
}
}
If I am doing wrong please let me know proper way to do it.