Skip to content

Commit

Permalink
WIP? cache please?
Browse files Browse the repository at this point in the history
  • Loading branch information
sz3 committed Jun 13, 2021
1 parent 99eb349 commit e20a3cd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@
<a id="invisible_click" href="javascript:;" onclick="Main.clickNav()"></a>

<script type="text/javascript">
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js');
}
var canvas = document.getElementById('canvas');

var Module = {};
Expand Down
7 changes: 0 additions & 7 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,3 @@ window.addEventListener("drop", function(e) {
Main.dragDrop(e);
document.body.style["opacity"] = 1.0;
}, false);

window.onload = function() {
'use strict';
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
}
}
3 changes: 2 additions & 1 deletion web/pwa.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"dir": "ltr",
"name": "Cimbar Encoder",
"short_name": "cimbar.org",
"icons": [],
"icons": [{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],
"scope": "/",
"start_url": "/index.html",
"display": "fullscreen",
"theme_color": "aliceblue",
"background_color": "black"
}

15 changes: 13 additions & 2 deletions web/sw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

var _cacheName = 'cimbar-js-pwa';
var _cacheName = 'cimbar-js-v0.5.8';
var _cacheFiles = [
'/',
'/index.html',
'/cimbar_js.js',
'/cimbar_js.wasm',
Expand All @@ -26,3 +25,15 @@ self.addEventListener('fetch', function(e) {
})
);
});

// clean old caches
self.addEventListener('activate', function(e) {
e.waitUntil(caches.keys().then(function(keyList) {
Promise.all(keyList.map(function(key) {
if (key === _cacheName) {
return;
}
caches.delete(key);
}));
})());
});

0 comments on commit e20a3cd

Please sign in to comment.