【问题标题】:Angular service worker not caching post requestsAngular Service Worker 不缓存发布请求
【发布时间】:2018-11-04 14:43:52
【问题描述】:

有谁知道角度服务工作者是否没有缓存帖子 要求 ?我使用@angular 5.2.5 将它集成到我的应用程序中 缓存一些请求,但其中一些是帖子,而那些他 即使它们与我指定的 urls 模式匹配,也不会缓存。 这是我的 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 没有被缓存并且 一个是发布请求,我尝试添加通配符以匹配 模式,但在 "/api/*", "/api/**/*", "/api/**/**/*", "/api/**/**/**/*" 上没有成功。

我在使用 chrome 测试我的网站时遇到问题 因为对于我们正在使用的内部生产环境 自签名证书有人知道解决方法吗?一世 试过this response 但是 chrome 仍然显示错误并且 service worker 没有运行

【问题讨论】:

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


    【解决方案1】:

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

    这里有一些 PouchDB 入门的参考文章

    【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-07-22
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多