角度服务工作者不缓存帖子请求

时间:2018-05-25 08:48:50

标签: angular google-chrome service-worker angular-service-worker

有没有人知道角度服务工作者是否没有缓存帖子 要求 ?我使用@angular 5.2.5将它集成到我的应用程序中 缓存一些请求,但其中一些是帖子,而那些是他 即使它们与我指定的urls patern匹配也不会缓存。 这是我的ngsw-config.json

{
  "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/**"
        ],
        "urls": [
          "**/fonts.googleapis.com/**/*",
          "**/www.gstatic.com/**/*"
        ]
      }
    }
  ],
  "dataGroups": [
    {
      "name": "api-performance",
      "urls": [
        "/api/attachments/*"
      ],
      "cacheConfig": {
        "maxSize": 200,
        "maxAge": "7d",
        "timeout": "10s",
        "strategy": "performance"
      }
    },
    {
      "name": "api-freshness",
      "urls": [
        "/api/*",
        "/api/**/*",
        "/api/**/**/*",
        "/api/**/**/**/*",
        "/api/views/*",
        "/api/app-structure",
        "/api/workflow/view",
        "/api/issues/*",
        "/.well-known",
        "/certs"
      ],
      "cacheConfig": {
        "maxSize": 200,
        "maxAge": "2d",
        "timeout": "10s",
        "strategy": "freshness"
      }
    }
  ]
}

这是为了测试而添加的,因为/ views不是缓存的 一个是帖子请求,我试图添加whildcards来匹配 模式,但没有成功"/api/*", "/api/**/*", "/api/**/**/*", "/api/**/**/**/*"

我在使用chrome测试生产版本中的网站时遇到问题 因为我们的内部生产就像我们正在使用的环境 自签名证书有没有人知道解决方法?一世 试过this response 但是chrome仍然显示错误,服务工作者没有运行

2 个答案:

答案 0 :(得分:3)

Angular Service Worker不会缓存帖子请求,在我看来这是一个正确的设计原则。如果您尝试在离线时添加记录并希望在联机时与服务器数据同步,则可以尝试使用IndexedDb或PouchDb(无缝同步的JavaScript数据库)。

以下是一些开始使用PouchDB的参考文章

答案 1 :(得分:0)

这不是Angular的问题,这是由于服务工作者的功能造成的。目前,服务人员不缓存任何发布请求。请关注此讨论以获取更多详细信息,https://github.com/w3c/ServiceWorker/issues/977

相关问题