diff options
author | Andrew Dolgov <[email protected]> | 2017-02-27 09:28:19 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-02-27 09:28:19 +0300 |
commit | bc720234f59d39119c9486ff88f248bacd3140c3 (patch) | |
tree | 2c7f644d92e2eaf8396f82069765ab1a8cb7a791 /js | |
parent | 4b4ffcd07902742d7b382d95e1c064bdff0f2308 (diff) |
periodically refresh worker cache on index load
Diffstat (limited to 'js')
-rw-r--r-- | js/index.js | 15 |
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"); |