元问答栏目视频美女
  1. 编程问答
  2. 答案列表

怎么解决:Failed to execute put on Cache :Request method POST is unsupported

回答列表
很简单,加上判断就行,如果是get请求就缓存,不然就不缓存。
self.addeventlistener('fetch',event =>{
event.respondwith(。
caches.match(event.request).then(response =>{
if (response) {
//found cached resource
return response;
}
// get resource and add it to cache
return fetch(event.request)。
then(response =>{
// check if the response is valid
if (!response.ok) {
return response;
}
if(event.request.method=='get'){
const newresponse = response.clone();
caches.open(cache_name).then(cache =>cache.put(event.request,newresponse)。
);
}
return response;
});
})。
);
});
猜你喜欢
相关推荐