summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-27 09:28:19 +0300
committerAndrew Dolgov <[email protected]>2017-02-27 09:28:19 +0300
commitbc720234f59d39119c9486ff88f248bacd3140c3 (patch)
tree2c7f644d92e2eaf8396f82069765ab1a8cb7a791 /js
parent4b4ffcd07902742d7b382d95e1c064bdff0f2308 (diff)
periodically refresh worker cache on index load
Diffstat (limited to 'js')
-rw-r--r--js/index.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/js/index.js b/js/index.js
index c5f8926..336232f 100644
--- a/js/index.js
+++ b/js/index.js
@@ -1,3 +1,18 @@
+function cache_refresh() {
+ if ('serviceWorker' in navigator) {
+ localforage.getItem("epube-cache.timestamp").then(function(stamp) {
+ var ts = parseInt(new Date().getTime()/1000);
+
+ if (!stamp || ts - stamp > 3600) {
+ console.log('asking worker to refresh cache');
+ navigator.serviceWorker.controller.postMessage("refresh-cache");
+ localforage.setItem("epube-cache.timestamp", ts);
+ }
+
+ });
+ }
+}
+
function mark_offline(elem) {
var bookId = elem.getAttribute("data-book-id");