Service worker not run in offline mode using nodejs server

半城伤御伤魂 提交于 2019-12-05 13:19:18
B. B.

I posted a similar question here and got an answer : Service Worker not working in Offline mode with node js server

To make it short, keep in mind the service worker's scope is its own directory and folders below... and it cannot access your lib or app directories...

In more detail, this means that if your content starts at https://example.com/, your service worker must live at https://example.com/service-worker.js. It won't function right if you put it as https://example.com/js/service-worker.js.

The service worker is just a javascript file served from your webserver. It doesn't matter if it's node.js or not.

Have you checked the 'application' tab in the chrome debugging tools to see if the service worker is loaded? If it is, please share the code of your 'service-worker.js' file. You can also add a 'catch' part when registering the service worker. That may show you what is going on if the service worker can't be loaded.

window.addEventListener('load', function() {
		navigator.serviceWorker
    .register('./service-worker.js')
    .then(function() { console.log('Service Worker Registered'); })
    
    .catch(function (err) {
            console.log('ServiceWorker registration failed: ', err);
    });
    
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!