【发布时间】:2016-06-27 19:45:49
【问题描述】:
我正在处理服务人员,在 fetch 事件中,我希望所有请求都保存在我的数组中,但是当我在控制台记录 fetch(event.request) 时,它只返回一个承诺。如何使用 fetch API 保存图像所有图像请求。我是服务工作者的新手。请帮忙。谢谢你。
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response){
if(response){
return response; // get the element from the cache
}
/*save the fetch(event.request) link to array*/
return fetch(event.request);// How toget the element from the network
})
);
});
【问题讨论】:
标签: javascript caching fetch service-worker