mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 22:36:09 +03:00
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
// Copyright 2018 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// @ts-check
|
|
'use strict';
|
|
|
|
const cacheName = '{{cache_hash}}';
|
|
const filesToCache = [
|
|
'favicon.ico',
|
|
'index.html',
|
|
'infocard-ui.js',
|
|
'infocard.css',
|
|
'main.css',
|
|
'manifest.json',
|
|
'options.css',
|
|
'shared.js',
|
|
'start-worker.js',
|
|
'state.js',
|
|
'tree-ui.js',
|
|
'tree-worker.js',
|
|
];
|
|
|
|
// On install, cache the items in the `filesToCache` list
|
|
self.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(cacheName).then(cache => cache.addAll(filesToCache))
|
|
);
|
|
});
|
|
|
|
// On activate, remove any old caches
|
|
self.addEventListener('activate', event => {
|
|
async function deleteOldCache(key) {
|
|
if (key !== cacheName) {
|
|
return caches.delete(key);
|
|
}
|
|
}
|
|
|
|
event.waitUntil(
|
|
caches.keys().then(keyList => Promise.all(keyList.map(deleteOldCache)))
|
|
);
|
|
return self.clients.claim();
|
|
});
|
|
|
|
// On fetch, return entries from the cache if possible
|
|
self.addEventListener('fetch', event => {
|
|
event.respondWith(
|
|
caches
|
|
.match(event.request, {ignoreSearch: true})
|
|
.then(response => response || fetch(event.request))
|
|
);
|
|
});
|