fix huge sw blunder - webgbcam - [fork] gameboy webcam
HTML git clone git://src.adamsgaard.dk/webgbcam
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 402f9daad77839b93acb48cfb10e8cef8f5d7491
DIR parent 850f60a0e9c312dd1357ffb6211df0e11b8b8296
HTML Author: Erin Pinheiro <erin.pinheiro@usp.br>
Date: Wed, 27 Apr 2022 03:43:34 +0000
fix huge sw blunder
Diffstat:
M sw.js | 99 +++++++++++++++----------------
1 file changed, 47 insertions(+), 52 deletions(-)
---
DIR diff --git a/sw.js b/sw.js
@@ -1,44 +1,39 @@
const cacheName = 'webgbcam-v3.3'
self.addEventListener('install', function(e) {
- e.waitUntil(
- caches.open(cacheName).then(function(cache) {
- return cache.addAll([
- '.',
- 'index.html',
- 'style.css',
- 'app.js',
- 'bg.png',
- 'mac-frame.png',
- 'ui-capture.png',
- 'ui-settings.png',
- 'ui-main.png',
- 'ui-hidden.png',
- 'ui-timer.png',
- 'ui-record.png',
- 'loading.gif',
- 'gifjs/gif.js',
- 'gifjs/gif.worker.js'
- ]);
- })
- );
+e.waitUntil(
+ caches.open(cacheName).then(function(cache) {
+ return cache.addAll([
+ '.',
+ 'index.html',
+ 'style.css',
+ 'app.js',
+ 'bg.png',
+ 'mac-frame.png',
+ 'ui-capture.png',
+ 'ui-settings.png',
+ 'ui-main.png',
+ 'ui-hidden.png',
+ 'ui-timer.png',
+ 'ui-record.png',
+ 'loading.gif',
+ 'gifjs/gif.js',
+ 'gifjs/gif.worker.js'
+ ]);
+ })
+);
});
-// this is supposed to invalidate old caches, i think. i don't know. stackoverflow
self.addEventListener('activate', function(event) {
- event.waitUntil(
- caches.keys().then(function(cacheNames) {
- return Promise.all(
- cacheNames.filter(function(cacheName) {
- // Return true if you want to remove this cache,
- // but remember that caches are shared across
- // the whole origin
- }).map(function(cacheName) {
- return caches.delete(cacheName);
- })
- );
- })
- );
+ event.waitUntil(
+ caches.keys().then(function(keyList) {
+ return Promise.all(keyList.map(function(key) {
+ if (key != cacheName) {
+ return caches.delete(key);
+ }
+ }));
+ })
+ );
});
// The fetch handler serves responses for same-origin resources from a cache.
@@ -46,22 +41,22 @@ self.addEventListener('activate', function(event) {
// from the network before returning it to the page.
self.addEventListener('fetch', event => {
// Skip cross-origin requests, like those for Google Analytics.
- if (event.request.url.startsWith(self.location.origin)) {
- event.respondWith(
- caches.match(event.request).then(cachedResponse => {
- if (cachedResponse) {
- return cachedResponse;
- }
+ if (event.request.url.startsWith(self.location.origin)) {
+ event.respondWith(
+ caches.match(event.request).then(cachedResponse => {
+ if (cachedResponse) {
+ return cachedResponse;
+ }
- return caches.open(cacheName).then(cache => {
- return fetch(event.request).then(response => {
- // Put a copy of the response in the runtime cache.
- return cache.put(event.request, response.clone()).then(() => {
- return response;
- });
- });
- });
- })
- );
- }
+ return caches.open(cacheName).then(cache => {
+ return fetch(event.request).then(response => {
+ // Put a copy of the response in the runtime cache.
+ return cache.put(event.request, response.clone()).then(() => {
+ return response;
+ });
+ });
+ });
+ })
+ );
+ }
});
\ No newline at end of file