summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php1
-rw-r--r--js/index.js15
2 files changed, 16 insertions, 0 deletions
diff --git a/index.php b/index.php
index 114403b..c3dd32b 100644
--- a/index.php
+++ b/index.php
@@ -93,6 +93,7 @@
}
mark_offline_books();
+ cache_refresh();
});
</script>
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");