javascript - How to serve service-worker.js from spring boot properly? -


the browser complains file behind redirect:

domexception: failed register serviceworker:  script resource behind redirect, disallowed. 

what tried far:

service worker on `static/service-worker.js` service worker on @getmapping("/service-worker.js") @responsebody 

in both cases can read file brower in /service-worker.js registration fails same exception.

edit: (this registration had problems with)

<script> if ('serviceworker' in navigator) {     console.log("will service worker register?");     navigator.serviceworker.register('service-worker.js')         .then(function(reg){             console.log("yes, did.");         }).catch(function(err) {         console.log("no didn't. happened: ", err)     }); } </script> 

my script trying register in /store/all. registering navigator.serviceworker.register('service-worker.js') calling /store/service-worker.js being redirected according rule had programmed in controller.

the right call should be: navigator.serviceworker.register('/service-worker.js') ensures call service-worker.js in root , not in same path current page.

tl;dr missing /


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -