Don't cache app assets on Cordova or NW.js platforms
This commit is contained in:
parent
7f215b850c
commit
c5efd7c3e7
19
www/cache.js
19
www/cache.js
@ -126,6 +126,8 @@ for (i in SETTINGS.weathericons) {
|
|||||||
cachedurls.push("assets/images/weather-" + SETTINGS.weathericons[i] + ".svg");
|
cachedurls.push("assets/images/weather-" + SETTINGS.weathericons[i] + ".svg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cacheFilled = false;
|
||||||
|
|
||||||
function fillCache(cachename) {
|
function fillCache(cachename) {
|
||||||
if ('caches' in window) {
|
if ('caches' in window) {
|
||||||
// delete old caches
|
// delete old caches
|
||||||
@ -137,15 +139,22 @@ function fillCache(cachename) {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cacheFilled = true; // assume good
|
||||||
caches.open(cachename).then(function (cache) {
|
caches.open(cachename).then(function (cache) {
|
||||||
for (i in cachedurls) {
|
for (i in cachedurls) {
|
||||||
cache.add(cachedurls[i]);
|
try {
|
||||||
|
cache.add(cachedurls[i]);
|
||||||
|
} catch (ex) {
|
||||||
|
cacheFilled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Do it again in a little while to reduce chance of errors
|
// Do it again in a little while
|
||||||
setTimeout(function () {
|
if (!cacheFilled) {
|
||||||
fillCache(cachename);
|
setTimeout(function () {
|
||||||
}, 1000 * 30);
|
fillCache(cachename);
|
||||||
|
}, 1000 * 30);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -69,7 +69,9 @@
|
|||||||
<script src="cache.js"></script>
|
<script src="cache.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
fillCache(SETTINGS.cacheversion);
|
if (platform_type == "browser") {
|
||||||
|
fillCache(SETTINGS.cacheversion);
|
||||||
|
}
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('sw.js').then(function (registration) {
|
navigator.serviceWorker.register('sw.js').then(function (registration) {
|
||||||
console.log('Service worker registration succeeded:', registration);
|
console.log('Service worker registration succeeded:', registration);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var SETTINGS = {
|
var SETTINGS = {
|
||||||
cacheversion: "v1.4.0_3",
|
cacheversion: "v1.4.0_4",
|
||||||
maptileurls: {
|
maptileurls: {
|
||||||
liberty: {
|
liberty: {
|
||||||
url: "https://maps.netsyms.net/styles/osm-liberty/{z}/{x}/{y}.png",
|
url: "https://maps.netsyms.net/styles/osm-liberty/{z}/{x}/{y}.png",
|
||||||
|
32
www/sw.js
32
www/sw.js
@ -4,29 +4,33 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var cachename = "v1.4.0_3";
|
var cachename = "v1.4.0_4";
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.match(event.request).then((resp) => {
|
caches.match(event.request).then((resp) => {
|
||||||
return resp || fetch(event.request).then((response) => {
|
return resp || fetch(event.request).then((response) => {
|
||||||
return caches.open(cachename).then((cache) => {
|
return caches.open(cachename).then((cache) => {
|
||||||
cache.put(event.request, response.clone());
|
try {
|
||||||
|
cache.put(event.request, response.clone());
|
||||||
|
} catch (ex) {
|
||||||
|
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
//
|
||||||
self.addEventListener('install', function (event) {
|
//self.addEventListener('install', function (event) {
|
||||||
event.waitUntil(
|
// event.waitUntil(
|
||||||
caches.open(cachename).then((cache) => {
|
// caches.open(cachename).then((cache) => {
|
||||||
return cache.addAll([
|
// return cache.addAll([
|
||||||
"https://maps.netsyms.net/styles/osm-liberty/style.json",
|
// "https://maps.netsyms.net/styles/osm-liberty/style.json",
|
||||||
"https://maps.netsyms.net/styles/klokantech-terrain/style.json",
|
// "https://maps.netsyms.net/styles/klokantech-terrain/style.json",
|
||||||
"https://maps.netsyms.net/styles/fiord-color/style.json",
|
// "https://maps.netsyms.net/styles/fiord-color/style.json",
|
||||||
"https://maps.netsyms.net/styles/oled-black/style.json"
|
// "https://maps.netsyms.net/styles/oled-black/style.json"
|
||||||
]);
|
// ]);
|
||||||
}));
|
// }));
|
||||||
});
|
//});
|
Loading…
x
Reference in New Issue
Block a user