My application is based on subdomains and I am trying to use service workers in my application.
How do I run service worker on abc.localhost.com . I understand google has not whitelisted subdomains on localhost to use service workers but is there a work around?
I cannot get service worker to work in development mode.
There is app folder that has the application content.
If I register service-worker in app folder, I cannot cache bower components and then app does not work offline.
If I register service worker outside of app folder, index.html which is in app folder, is never able to find path of servie-worker.js which is outside of app folder, in the root directory.
I have tried this in index.html:
if( 'serviceWorker' in navigator ) {
navigator.serviceWorker
.register( '../service-worker.js' , { scope : ' ' } )
.then( function( ) {
console.log('Congratulations!!Service Worker Registered');
})
.catch( function( err) {
console.log(`Aagh! Some kind of Error :- ${err}`);
});
} else {
console.log("SW NOT SUPPORTED");
//still not supported
}
But I only get 404.
I have also tried using absolute path i.e
.register( '/service-worker.js' , { scope : ' ' } )