From bc720234f59d39119c9486ff88f248bacd3140c3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 27 Feb 2017 09:28:19 +0300 Subject: periodically refresh worker cache on index load --- js/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'js/index.js') 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"); -- cgit v1.2.3