【问题标题】:Angular service worker manifest.webmanifest hash mismatchAngular Service Worker manifest.webmanifest 哈希不匹配
【发布时间】:2021-12-19 21:34:22
【问题描述】:

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

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

【问题讨论】:

    标签: angular service-worker


    【解决方案1】:

    好的,哈希不匹配 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 小时后遵循此答案。我找到了这个: https://stackoverflow.com/a/62935101/5748537

    "。默认情况下,git会替换行尾。这导致服务器上的文件与原始文件不同,它们的哈希值也不同。"

    所以我们把它改成 git config --local core.autocrlf false 我们完成了!

    【讨论】:

      猜你喜欢
      • 2020-02-10
      • 1970-01-01
      • 2020-10-23
      • 2021-04-23
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      相关资源
      最近更新 更多