1let version = 'astrolink-assets-v' + getVersion(); 2 3var files = [ 4 // Js 5 '/assets/js/vendor.js', 6 '/assets/js/common.module.js', 7 '/assets/js/navigation.module.js', 8 // Css 9 '/assets/css/ui.css', 10 '/assets/css/common.module.css', 11 '/assets/css/menuaccount.container.css', 12 '/assets/css/notifications.container.css', 13 '/assets/css/navigation.module.css', 14 // Fonts 15 '/assets/fonts/Lato-300/Lato-300.woff2', 16 '/assets/fonts/Lato-700/Lato-700.woff2', 17 '/assets/fonts/Lato-900/Lato-900.woff2', 18 '/assets/fonts/Lato-regular/Lato-regular.woff2', 19 // Images 20 '/assets/images/logo-footer.svg', 21 '/assets/images/logo.svg', 22 '/assets/images/signs-element.svg', 23 '/assets/images/signs/aquario.svg', 24 '/assets/images/signs/aries.svg', 25 '/assets/images/signs/cancer.svg', 26 '/assets/images/signs/capricornio.svg', 27 '/assets/images/signs/escorpiao.svg', 28 '/assets/images/signs/gemeos.svg', 29 '/assets/images/signs/leao.svg', 30 '/assets/images/signs/libra.svg', 31 '/assets/images/signs/peixes.svg', 32 '/assets/images/signs/sagitario.svg', 33 '/assets/images/signs/touro.svg', 34 '/assets/images/signs/virgem.svg', 35]; 36 37self.addEventListener('install', (e) => { 38 console.log(version + ' installing...'); 39 e.waitUntil( 40 caches.open(version).then((cache) => { 41 return cache.addAll(files); 42 }) 43 ); 44}); 45 46self.addEventListener('fetch', (event) => { 47 event.respondWith( 48 49 caches.match(event.request).then((cachedResponse) => { 50 51 if (cachedResponse) { 52 console.log('Found ', event.request.url, ' in cache'); 53 return cachedResponse; 54 } 55 56 console.log('Network request for ', event.request.url); 57 58 return fetch(event.request).then((response) =>{ 59 60 console.log(response); 61 62 if(!response.ok) { 63 return response; 64 } 65 66 if (event.request.method == 'POST') { 67 return response; 68 } 69 70 return caches.open(version).then((cache) => { 71 if (event.request.url.indexOf('test') < 0) { 72 cache.put(event.request.url, response.clone()); 73 } 74 return response; 75 }); 76 }); 77 78 }).catch((error) => { 79 //todo: criar site offline 80 console.info('apply site offline mode'); 81 }) 82 ); 83}); 84 85self.addEventListener('activate', (event) => { 86 var cacheWhitelist = [version]; 87 event.waitUntil( 88 caches.keys().then((cacheNames) => { 89 return Promise.all( 90 cacheNames.filter((cacheName) => { 91 if(cacheWhitelist.indexOf(cacheName) === -1) { 92 return caches.delete(cacheName); 93 } 94 }).map((cacheName) => { 95 return caches.delete(cacheName); 96 }) 97 ); 98 }) 99 ); 100}); 101 102self.onactivate = (event) => { 103 console.log('Activate', event); 104} 105self.onfetch = (event) => { 106 console.log('Fetch', event); 107}; 108 109function getVersion(){ 110 var field = 'v'; 111 var href = self.location.href; 112 var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i' ); 113 var string = reg.exec(href); 114 return string ? string[1] : '1'; 115}; 116 117if (!Cache.prototype.add) { 118 Cache.prototype.add = function add(request) { 119 return this.addAll([request]); 120 }; 121} 122 123if (!Cache.prototype.addAll) { 124 Cache.prototype.addAll = function addAll(requests) { 125 var cache = this; 126 127 function NetworkError(message) { 128 this.name = 'NetworkError'; 129 this.code = 19; 130 this.message = message; 131 } 132 NetworkError.prototype = Object.create(Error.prototype); 133 134 return Promise.resolve() 135 .then(function() { 136 if (arguments.length < 1) throw new TypeError(); 137 138 requests = requests.map(function(request) { 139 if (request instanceof Request) { 140 return request; 141 } else { 142 return String(request); } 143 }); 144 145 return Promise.all(requests.map(function(request) { 146 if (typeof request === 'string') {
147 request = new Request(request); 148 } 149 150 return fetch(request.clone()); 151 })); 152 }) 153 .then(function(responses) { 154 return Promise.all(responses.map(function(response, i) { 155 return cache.put(requests[i], response); 156 })); 157 }) 158 .then(function() { 159 return undefined; 160 }); 161 }; 162} 163 164if (!CacheStorage.prototype.match) { 165 CacheStorage.prototype.match = function match(request, opts) { 166 var caches = this; 167 return caches.keys().then(function(cacheNames) { 168 var match; 169 return cacheNames.reduce(function(chain, cacheName) { 170 return chain.then(function() { 171 return match || caches.open(cacheName).then(function(cache) { 172 return cache.match(request, opts); 173 }).then(function(response) { 174 match = response; 175 return match; 176 }); 177 }); 178 }, Promise.resolve()); 179 }); 180 }; 181}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.