mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-06-27 16:25:54 +00:00
added RUP/PPF/xdelta support, added webworkers for a huge performance boost, added localization, other small fixes
This commit is contained in:
parent
9d85db3baa
commit
e7d2bccc47
19 changed files with 3016 additions and 1750 deletions
|
@ -1,29 +1,42 @@
|
|||
/*
|
||||
original: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/basic/service-worker.js
|
||||
|
||||
Copyright 2016 Google Inc. All Rights Reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
---
|
||||
mod by marcrobledo, original from: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/basic/service-worker.js
|
||||
*/
|
||||
|
||||
const PRECACHE_ID='v20180926';
|
||||
const PRECACHE_FILES=[
|
||||
'index.html','./',
|
||||
'RomPatcher.css',
|
||||
'RomPatcher.js',
|
||||
'favicon.png',
|
||||
'logo192.png',
|
||||
'ips.js',
|
||||
'ups.js',
|
||||
'aps.js',
|
||||
'bps.js'
|
||||
|
||||
const PRECACHE = 'precache-v2';
|
||||
const RUNTIME = 'runtime';
|
||||
const PRECACHE_URLS = [
|
||||
'index.html','./',
|
||||
'manifest.json',
|
||||
'favicon.png',
|
||||
'logo192.png',
|
||||
'RomPatcher.css',
|
||||
'RomPatcher.js',
|
||||
'locale.js',
|
||||
'worker_apply.js',
|
||||
'worker_create.js',
|
||||
'worker_crc.js',
|
||||
'MarcFile.js',
|
||||
'crc.js',
|
||||
'ips.js',
|
||||
'ups.js',
|
||||
'aps.js',
|
||||
'bps.js',
|
||||
'rup.js',
|
||||
'ppf.js',
|
||||
'vcdiff.js'
|
||||
];
|
||||
|
||||
|
||||
self.addEventListener('install',event=>{event.waitUntil(caches.open(PRECACHE_ID).then(cache=>cache.addAll(PRECACHE_FILES)).then(self.skipWaiting()))});self.addEventListener('activate',event=>{const currentCaches=[PRECACHE_ID,'runtime'];event.waitUntil(caches.keys().then(cacheNames=>{return cacheNames.filter(cacheName=>!currentCaches.includes(cacheName));}).then(cachesToDelete=>{return Promise.all(cachesToDelete.map(cacheToDelete=>{return caches.delete(cacheToDelete);}))}).then(()=>self.clients.claim()))});self.addEventListener('fetch',event=>{if(event.request.url.startsWith(self.location.origin))event.respondWith(caches.match(event.request).then(cachedResponse=>{if(cachedResponse)return cachedResponse;return caches.open('runtime').then(cache=>{return fetch(event.request).then(response=>{return cache.put(event.request,response.clone()).then(()=>{return response})})})}))})
|
||||
self.addEventListener('install', event => {event.waitUntil(caches.open(PRECACHE).then(cache => cache.addAll(PRECACHE_URLS)).then(self.skipWaiting()));});self.addEventListener('activate', event => {const currentCaches = [PRECACHE, RUNTIME];event.waitUntil(caches.keys().then(cacheNames => {return cacheNames.filter(cacheName => !currentCaches.includes(cacheName));}).then(cachesToDelete => {return Promise.all(cachesToDelete.map(cacheToDelete => {return caches.delete(cacheToDelete);}));}).then(() => self.clients.claim()));});self.addEventListener('fetch', event => {if (event.request.url.startsWith(self.location.origin)) {event.respondWith(caches.match(event.request).then(cachedResponse => {if (cachedResponse) {return cachedResponse;}return caches.open(RUNTIME).then(cache => {return fetch(event.request).then(response => {return cache.put(event.request, response.clone()).then(() => {return response;});});});}));}});
|
Loading…
Add table
Add a link
Reference in a new issue