问题描述
我已经使用 angular 6 和 @angular/pwa 包构建了一个 PWA.
I've built a PWA using angular 6 and the @angular/pwa package.
我一直在尝试解决这个问题,但无论我做什么,我都会收到 start_url 错误.我试过了:
I've been trying to fix this but no matter what I do, I'm getting the start_url error. I have tried:
- 使用绝对链接
- 确保 start_url 在 SW 的范围内(sw 在主文件夹中)
- 使用我在其他支持线程中看到的文件名/index.html".
- 每次都清除所有浏览器历史记录和缓存.
- 在@angular/pwa 包上搜索 Github 问题
- 一般在谷歌搜索这个 PWA 问题.
这是我的清单:
{
"name": "BC Doc View",
"short_name": "BCview",
"theme_color": "#1976d2",
"background_color": "#fafafa",
"display": "standalone",
"scope": "/",
"start_url": "/",
在这段代码之后,只有一堆图标,与这篇文章无关.
After this piece of code there's just a bunch of icons, irrelevant to this post.
我对服务工作者的配置:
My configuration for the service worker:
{
"index": "/index.html",
"assetGroups": [
{
"name": "BC Doc View",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**"
我使用 ng build --prod 命令实际生成的 Service Worker 有 2200 行代码,所以我认为将其发布在这里没有意义.
My actual produced service worker using the ng build --prod command is 2200 lines of code so I don't think it would be relevant to post that here.
不知道我错过了什么.
推荐答案
我已经为这个错误哭了 3 小时,在我在这里发布后几分钟我找到了解决方案.
I've cried with this error for 3 hours, minutes after I post it here I found the solution.
我一直在将其测试到开发子域中并像访问 subdomain.domain.com/folder 一样访问它
I've been testing this into a dev subdomain and accessing it like subdomain.domain.com/folder
将所有内容放入主文件夹后,我的 PWA 得分为 100.
Once I've put everything in the main folder I'm getting a 100 PWA score.
https://i.imgur.com/ex3Os87.png
我还没有优化性能.
这篇关于Angular 6 @angular/pwa - sw 无法成功提供清单的 start_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!