forked from pazguille/sw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
36 lines (31 loc) · 800 Bytes
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
importScripts('serviceworker-cache-polyfill.js');
var CACHE_NAME = 'v1';
var urlsToCache = [
'https://code.jquery.com/jquery-2.1.4.min.js'
];
this.addEventListener('install', function(eve) {
eve.waitUntil(
caches.open(CACHE_NAME).then(function(cache) {
return cache.addAll(urlsToCache);
})
);
});
// Remove all caches
// this.addEventListener('activate', function(event) {
// event.waitUntil(
// caches.keys().then(function(keys) {
// // caches.delete('v1');
// keys.forEach(function(key) {
// caches.delete(key);
// })
// })
// );
// });
this.addEventListener('fetch', function(eve) {
eve.respondWith(
caches.match(eve.request).then(function(response) {
return response || fetch(eve.request);
})
);
});