Angular 服务工作者 manifest.webmanifest 哈希不匹配

Angular service worker manifest.webmanifest hash mismatch

你好,我的 service worker 有哈希不匹配问题,我猜是 facebook 导致了这个错误。我有问题:

  1. 如何跳过软件上的 facebook url 缓存?
  2. 如何强制重载?我的意思是强制更新,清除 service worker 本身

好的,哈希不匹配 manifest.webmanifest。问题是为什么我们会收到这个错误? 什么是哈希? 散列意味着您将文本散列为限制随机字符。它可以是一小行文字或一本书,没关系。都变成这样的随机字符:556dbd80aaaa6096e48da8e49505e6953991ce81 现在我的清单看起来像这样:

{
  "name": "reader-web",
  "short_name": "reader-web",
  "theme_color": "#1976d2",
  "background_color": "#fafafa",
  "display": "standalone",
  "scope": "./",
  "start_url": "./",
  "icons": [
    {
      "src": "assets/icons/icon-72x72.png",
      "sizes": "72x72",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-96x96.png",
      "sizes": "96x96",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-128x128.png",
      "sizes": "128x128",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-144x144.png",
      "sizes": "144x144",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-152x152.png",
      "sizes": "152x152",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-384x384.png",
      "sizes": "384x384",
      "type": "image/png",
      "purpose": "maskable any"
    },
    {
      "src": "assets/icons/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png",
      "purpose": "maskable any"
    }
  ]
}

并且它有这些 556dbd80aaaa6096e48da8e49505e6953991ce81 的散列。 在我的 MICROSOFT windows 10 台计算机上有这些哈希。 好的,我们通过 GIT 将该文件推送到服务器 然后服务器将它提供给客户端。客户端出现错误:



Debug log:

[23m49s182u] TypeError(Failed to fetch, TypeError: Failed to fetch
    at Driver.safeFetch (https://awread.vn/ngsw-worker.js:2796:41)
    at Driver.handleFetch (https://awread.vn/ngsw-worker.js:2240:33)) Driver.fetch(https://www.facebook.com/tr/?id=178697176886410&ev=fb_page_view&dl=https%3A%2F%2Fawread.vn%2F&rl=&if=false&ts=1639919002667&sw=1920&sh=1080&at=)
[23m48s718u] Error(Hash mismatch (cacheBustedFetchFromNetwork): https://awread.vn/manifest.webmanifest: expected 556dbd80aaaa6096e48da8e49505e6953991ce81, got bc11265797cbb7d7676a8e9838d3808c53a9cb32 (after cache busting), Error: Hash mismatch (cacheBustedFetchFromNetwork): https://awread.vn/manifest.webmanifest: expected 556dbd80aaaa6096e48da8e49505e6953991ce81, got bc11265797cbb7d7676a8e9838d3808c53a9cb32 (after cache busting)
    at PrefetchAssetGroup.cacheBustedFetchFromNetwork (https://awread.vn/ngsw-worker.js:759:35)
    at async PrefetchAssetGroup.fetchFromNetwork (https://awread.vn/ngsw-worker.js:695:25)
    at async PrefetchAssetGroup.fetchAndCacheOnce (https://awread.vn/ngsw-worker.js:658:29)
    at async PrefetchAssetGroup.handleFetch (https://awread.vn/ngsw-worker.js:514:29)
    at async https://awread.vn/ngsw-worker.js:1484:30
    at async AppVersion.handleFetch (https://awread.vn/ngsw-worker.js:1481:27)
    at async Driver.handleFetch (https://awread.vn/ngsw-worker.js:2221:31)) Driver.handleFetch(version: a38f1134bbce491571e14f75adc9ef27a23b4437)

等等……为什么?我们需要 556dbd80aaaa6096e48da8e49505e6953991ce81 但我们得到了 bc11265797cbb7d7676a8e9838d3808c53a9cb32? 通过以下方式检查服务器上的 manifest.webmanifest: sha1sum manifest.webmanifest 我们得到了 bc11265797cbb7d7676a8e9838d3808c53a9cb32

谁改的? 因为构建步骤?修改导致该错误的文件? 不... 因为 git 系统。调试 10 小时后遵循此答案。我找到了这个:

". By default, git replaces line endings. And this led to the fact that the files on the server were different from the original ones and their hashes was also different."

所以我们将其更改为 git config --local core.autocrlf false 我们完成了!