| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 this.onfetch = function(event) { | |
| 6 var CACHE_NAME = 'cache_name'; | |
| 7 var cache = undefined; | |
| 8 var url = event.request.url; | |
| 9 event.respondWith( | |
| 10 caches.open(CACHE_NAME) | |
| 11 .then(function(c) { | |
| 12 cache = c; | |
| 13 return cache.match(url); | |
| 14 }) | |
| 15 .then(function(response) { | |
| 16 if (response) | |
| 17 return response; | |
| 18 var cloned_response = undefined; | |
| 19 return fetch(url) | |
| 20 .then(function(res) { | |
| 21 cloned_response = res.clone(); | |
| 22 return cache.put(url, res); | |
| 23 }) | |
| 24 .then(function() { | |
| 25 return cloned_response; | |
| 26 }); | |
| 27 })); | |
| 28 }; | |
| OLD | NEW |