Angular Service Worker的外部图像缓存

时间:2018-08-10 18:22:08

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

我有一个来自外部示例的图像源,例如https://cdn.myserver.com.background.jpg,我无法由服务工作者对其进行缓存,当图像来自资产文件夹时,它可以工作,但是外部图像链接无法缓存。

请给我任何建议。谢谢

{
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html"
        ],
        "versionedFiles": [
          "/*.bundle.css",
          "/*.bundle.js",
          "/*.chunk.js"
        ]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**"
        ]
      }
    }
  ],
  "dataGroups": [
    {
      "name": "api-performance",
      "urls": [
        "http://127.0.0.1:3000/**"
      ],
      "cacheConfig": {
        "maxSize": 100,
        "maxAge": "3d",
        "strategy": "performance"
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:2)

您可以将该特定网址添加到

 {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**"
        ],
         "urls": [
"https://cdn.myserver.com.background.jpg" ]
      }
    }