【问题标题】:Angular 9 PWA Hash mismatch (cacheBustedFetchFromNetwork)Angular 9 PWA 哈希不匹配(cacheBustedFetchFromNetwork)
【发布时间】:2020-10-23 22:58:45
【问题描述】:

我有一个角度 PWA,它不会离线启动(http 错误 504)。当我检查 /ngsw/state 我得到这个错误:

Error: Hash mismatch (cacheBustedFetchFromNetwork): https://example.com/favicon.ico: expected 566d8535a3adc2f7210a8a890bdc50ec4f91f0e3, got 8e076950c4c615772d8d5d753e07377bab9f2f27 (after cache busting)
    at PrefetchAssetGroup.<anonymous> (https://example.com/ngsw-worker.js:734:35)
    at Generator.next (<anonymous>)
    at fulfilled (https://example.com/ngsw-worker.js:174:62))
Latest manifest hash: 5952e5e67f8b4ee7115ef9d519a346712927b608

使用 角 CLI:9.1.9 节点:12.16.1 角度:9.1.11

PWA 上的灯塔检查没有给我任何错误,并且在我使用 .htaccess 的 apache 服务器上重定向角度路由

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

任何人的想法?谢谢!

【问题讨论】:

  • 我认为这是路由的问题,因为有时当我在桌面浏览器中打开 pwa (example.com) 时,我会得到一个找不到页面,但如果我添加 /index.html ( example.com/index.html) 最后,然后它可以工作......但它是随机的

标签: angular progressive-web-apps angular-service-worker


【解决方案1】:

就我而言,问题与我使用 git 部署应用程序(使用 post-receive git hook)有关。默认情况下,git 会替换行尾。这导致服务器上的文件与原始文件不同,它们的哈希值也不同。

我比较了服务器上文件 index.html 的哈希值,它与 'ngsw.json' 文件中的值不同。

    sha1sum index.html
    04e691dbfae931bfd24513ac63d833bdfee3a1f6  index.html

禁用行尾转换后:

    git config --local core.autocrlf false

再次推送项目问题消失了,sha1sum index.html 向我显示了“ngsw.json”中的保存哈希。

【讨论】:

  • 感谢您的回答,是的,问题是我有一个将项目部署到服务器的 sh 脚本,并且该脚本还在 ng 构建过程之后更改了图标。所以我不得不改变它,在 ng 构建脚本之前改变图标 - 所以现在一切正常
  • 谢谢,这是正确答案,应该接受
猜你喜欢
  • 1970-01-01
  • 2021-04-23
  • 2011-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多