码迷,mamicode.com
首页 > 其他好文 > 详细

[PWA] 5. Hijacking one type of request

时间:2016-05-16 07:05:02      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

Previously we saw how to Hijacking all the reqest, but this is not useful. So now we want to see how to Hijacking one kind of request. For example we want servce worker only response to the request ends with ".jpg":

self.addEventListener(fetch, function(event) {
  // TODO: only respond to requests with a
  // url ending in ".jpg"
  if(event.request.url.endsWith(".jpg")){
    event.respondWith(
        fetch(/imgs/dr-evil.gif)
    );
  }
});

 

https://developer.mozilla.org/en-US/docs/Web/API/Request

[PWA] 5. Hijacking one type of request

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5496820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!