service worker 在iis下注册范围的设置

注册时,可以设置scope,来超出所在文件夹:

navigator.serviceWorker.register('/scripts/script.js', { scope: '/' })

在web.config中,设置header

<configuration>
<location path="Scripts/script.js">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Service-Worker-Allowed" value="/" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>

运行后,不会报Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.错误

posted @ 2018-09-13 10:30  yt风往南吹  阅读(563)  评论(0)    收藏  举报