would you please tell me what i did wrong with my service worker installation, i have those errors appear in chrome console (see the image).
The script resource is behind a redirect, which is disallowed. service-worker.js:1
Failed to load resource: net::ERR_UNSAFE_REDIRECT https://harampress.com/post/45/service-worker.js
i use Laravel framework in backend if that could help
thank you.
I don't think the spec forbids redirects on the script. Do you get this error in firefox? This may be a chrome bug.
Oh, I was looking at Fetch a classic worker script, but the service worker spec does say to use error for the redirect mode. So I guess this is spec'd.
@wanderview i don't see this error anywhere in firefox console (developer edition - version 51.0a2), like you said it could be a bug with chrome console, maybe, i really don't know.
just to know that my service-worker.js is in the root of the website, works fine on home page no errors on chrome console, but the moment i try to navigate to a post for example, those two errors appears (see image).
knowing that i use sw-precache and sw-toolbox, i generate the service worker useing sw-precache with gulp.
Is this a blog? Do you really have a service worker hosted for each post? The URL in your image is /post/67/serviceworker.js.
yes it's a sort of blog
No, i don't really have a service worker hosted for each post, i have one service-worker.js in the root of my website.
Ok, then perhaps chrome is complaining about getting a 404 for the service worker script? It seems you might be registering a non-existent script from your blog post documents. Is your register() call to /serviceworker.js' or justserviceworker.js'? What does your local server see?
sorry @wanderview but i really didn't get what you're saying, would you please reform you answer, thank you
What @wanderview means is that when you do
navigator.serviceWorker.register('/sw.js')
The actual requesting URL is the sw.js located in the root
but when you do
navigator.serviceWorker.register('sw.js')
This is actually a Relative URL so what you actually request might be /post/blah/sw.js and your server might treat it as 404 and do some redirect.
@wanderview @Huxpro thank you for your help,
@Huxpro thank you for clarifying @wanderview 's answer ^^
i added the slash and it look like the two error messages disappeared
Most helpful comment
What @wanderview means is that when you do
The actual requesting URL is the
sw.jslocated in the rootbut when you do
This is actually a Relative URL so what you actually request might be
/post/blah/sw.jsand your server might treat it as 404 and do some redirect.