简体   繁体   English

服务人员无法加载资源:net :: ERR_UNSAFE_REDIRECT

[英]Service worker Failed to load resource: net::ERR_UNSAFE_REDIRECT

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-1). 您能告诉我我的Service Worker安装有什么问题吗,我在chrome控制台中出现了这些错误(请参见图1)。

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 我可以在后端使用Laravel框架,如果有帮助的话

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-2). 只是知道我的service-worker.js位于网站的根目录下,可以在首页上正常运行,而在chrome控制台上没有错误,但是例如,当我尝试导航到某个帖子时,就会出现这两个错误(请参见图片- 2)。

knowing that i use sw-precache and sw-toolbox, i generate the service worker useing sw-precache with gulp. 知道我使用了sw-precache和sw-toolbox,我生成了使用sw-precache和gulp的服务工作者。

image-1 图像-1

image-2 图像-2-

see the solutions here on github discussion 看到解决方案在这里 GitHub上讨论

the message from the discussion in github that actually answered to my problem : 来自github中讨论的消息实际上回答了我的问题:


What @wanderview means is that when you do @wanderview的意思是,当您这样做时

navigator.serviceWorker.register('/sw.js')

The actual requesting URL is the sw.js located in the root 实际的请求URL是位于根目录中的sw.js

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. 这实际上是一个相对URL,因此您实际请求的可能是/post/blah/sw.js ,服务器可能会将其视为404并进行一些重定向。


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM