不支持工作箱请求方法“POST”

问题描述 投票:1回答:1

我正在使用此站点的代码:https://developers.google.com/web/tools/workbox/modules/workbox-routing

我的代码如下:

workbox.routing.registerRoute(
  new RegExp('http://localhost:64445.*/'),
  workbox.strategies.staleWhileRevalidate({
    cacheName:'Post-Run-time-cache'
  }),
  'POST'
);

它给了我错误:

Uncaught (in promise) TypeError: Request method 'POST' is unsupported

我不知道出了什么问题。它来自文件,但不支持?为什么。谢谢您的帮助。

service-worker workbox
1个回答
3
投票

Cache Storage API不支持使用Request不是method作为缓存键的'GET'对象。尝试在缓存中存储'POST'请求(这在staleWhileRevalidate策略中引起了讨论)将会失败并出现类似于您所看到的错误 - 尽管我认为当您处于Workbox开发阶段时会记录更多信息错误模式,在localhost

如果你想重试失败的'POST'请求,我建议你使用workbox-background-sync module

© www.soinside.com 2019 - 2024. All rights reserved.