首页 文章

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

提问于
浏览
3

有谁知道角度服务工作者是否没有缓存帖子请求?我使用@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没有被缓存,而且一个是post请求,我试图添加whildcards来匹配模式但是没有成功 "/api/*", "/api/**/*", "/api/**/**/*", "/api/**/**/**/*" .

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

1 回答

  • 3

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

    以下是一些PouchDB入门的参考文章

相关问题