workbox - 如何在 workbox-config.js 中为 POST 操作配置 runtimeCaching
问题描述
我正在工作箱中为“POST”操作进行后台队列配置。请指导我在 workbox-config.js 中的“runtimeCaching”配置中为“POST”操作提供选项的位置
module.exports = {
"globDirectory": "dist/",
"globPatterns": [
"**/*.{txt,ico,html,js,css}"
],
"swDest": "dist\\sw.js",
runtimeCaching: [{
urlPattern: /api/,
handler: 'NetworkOnly',
options: {
// Configure background sync.
backgroundSync: {
name: 'product-bgsync-queue1',
options: {
maxRetentionTime: 24 * 60 * 60,
},
},
},
}]
};
上面的代码在 dist/sw.js 中为“GET”生成默认配置。
workbox.routing.registerRoute(/api/,
new workbox.strategies.NetworkOnly({
plugins:[
new workbox.backgroundSync.Plugin("product-bgsync-queue1",
{
maxRetentionTime:86400
} )
]
}),
'GET');
请指导如何为“POST”操作生成相同的配置。
解决方案
添加method: 'POST'
应该会给你你想要的行为:
runtimeCaching: [{
urlPattern: /api/,
handler: 'NetworkOnly',
method: 'POST',
options: {
// Configure background sync.
backgroundSync: {
name: 'product-bgsync-queue1',
options: {
maxRetentionTime: 24 * 60 * 60,
},
},
},
}]
推荐阅读
- python - Change datatype to be integer instead of string in JSON / Python print output
- django - 将过滤选项传递给 django DRF 中的嵌套序列化程序
- r - Transform a data.frame into a time series data as list
- java - 这个带有非聚合列的 cassandra 查询的定义行为是什么?
- python - No sound from MIDI program in Python on Mac
- jquery - 为什么我必须按两次按钮才能播放音频?
- javascript - 我可以使用数据流创建 S3 putObject 预签名 URL 吗?
- c# - Unity3D - 无法将 JSON 反序列化为对象
- javascript - IOS上的react-native-twitter Oath URLSearchParams错误
- javascript - d3 - 带圆圈的正弦波,问题是圆圈在曲线中重叠