I have an apache server running. The backend as such is supported by django but placed on apache server. I have a service worker which otherwise works completely fine. Here's the code which does the registration
navigator.serviceWorker.register('/static/js/components/sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(){console.log("success")})
But the above code somehow never gives any response. The promise remains in pending state. Even adding a catch at the end doesn give any error. It goes to the navigator.serviceworker.ready but doesnt not resolve into the then function. I'm not sure what is the problem.
I've tried the following stuffs:
I though the problem may be that service workers needs to be in same origin and all so i added header called Service-Worker-Allowed:/static but that didnt do the job.
When i accessed the file by directly going to the path were html is saved (eg: mywebsite/static/serviceworker.html) after adding Service-Worker-Allowed: /static It worked fine. But when i accessed the same html file by using the url mapped by django(i.e the url which i mapped through urls.py, eg: mywebsite/admin/worker ), it doesn seem to work.
Tried to give relative paths, but relative paths doesn work in my case.
- I put this on another apache server and there it seems to work fine.
I'm out of all ideas. Is this some django problem?