我将Angular 5.2.7与Angular Service Worker 5.2.7一起使用。
I use Angular 5.2.7 with Angular Service Worker 5.2.7.
我想缓存Web服务调用。因此,我在ngsw-config.json中有了此配置,用于dataGroups:
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" } }]我尝试缓存这两个URL: randomuser.me/api/?results=20 --->可以, test.moodlecloud/webservice/rest/server.php - ->是KO
I try to cache this two URLs : randomuser.me/api/?results=20 ---> It's OK test.moodlecloud/webservice/rest/server.php ---> It's KO
第一个按预期方式被缓存。这是一个简单的GET服务。 第二个不是。
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 ?
推荐答案服务工作者API 不允许POST / PUT请求。
Service Worker API does not allow POST/PUT requests.
在此博客文章展示了一个示例,说明了如何使用Indexed Db(如Roman Gherta的建议)来存储POST / PUT请求。
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.
在 Mozilla资源上也建议使用此解决方案。
更多推荐
带有POST请求的Angular Service Worker
发布评论