Angular Service Worker with POST request

你离开我真会死。 提交于 2019-12-10 21:22:52

问题


I use Angular 5.2.7 with Angular Service Worker 5.2.7.

I want to cache webservices calls. So, I've got with this config in my ngsw-config.json, for dataGroups :

"dataGroups": [{
  "name": "tasks-users-api",
  "urls": ["/api", "/rest"],
  "cacheConfig": {
    "strategy": "freshness",
    "maxSize": 20000,
    "maxAge": "1h",
    "timeout": "5s"
  }
}]

I try to cache this two URLs : https://randomuser.me/api/?results=20 ---> It's OK https://test.moodlecloud.com/webservice/rest/server.php ---> It's KO

The first one is cached as expected. It's a simple GET service. The second one isn't. It's a POST service with a form data sent as payload.

Any idea of what is wrong with that ?


回答1:


Service Worker API does not allow POST/PUT requests.

In this blog article it is showed an example on how you can use Indexed Db (as suggested by Roman Gherta) to store POST/PUT requests.

This solution is also suggested on Mozilla resource.



来源:https://stackoverflow.com/questions/49101130/angular-service-worker-with-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!