forked from Netsyms/PackageHelper
Improve caching of map tiles and everything else
parent
08d7ff224d
commit
af783bb415
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
|
||||
var cachedurls = [
|
||||
'package.json',
|
||||
'settings.js',
|
||||
'index.html',
|
||||
'.',
|
||||
'routes.js',
|
||||
'cache.js',
|
||||
|
||||
'assets/audio/error.mp3',
|
||||
'assets/audio/ok.mp3',
|
||||
'assets/audio/scan.mp3',
|
||||
|
||||
'assets/images/icons/logo.svg',
|
||||
'assets/images/barcode-dashed.svg',
|
||||
'assets/images/boxes.png',
|
||||
'assets/images/box-open-dashed.svg',
|
||||
'assets/images/box.png',
|
||||
'assets/images/check.png',
|
||||
'assets/images/envelope.png',
|
||||
'assets/images/envelopes.png',
|
||||
'assets/images/express.png',
|
||||
'assets/images/history-dashed.svg',
|
||||
'assets/images/largeboxes.png',
|
||||
'assets/images/largebox.png',
|
||||
'assets/images/multiple-items.png',
|
||||
'assets/images/note-dashed.svg',
|
||||
'assets/images/signature.png',
|
||||
'assets/images/signatures.png',
|
||||
'assets/images/smallpackage.png',
|
||||
'assets/images/smallpackages.png',
|
||||
|
||||
'assets/css/app.css',
|
||||
'assets/css/backdrop.css',
|
||||
'assets/css/oled.css',
|
||||
'assets/css/web-barcode.css',
|
||||
|
||||
'assets/js/audio.js',
|
||||
'assets/js/autofill.js',
|
||||
'assets/js/list.js',
|
||||
'assets/js/location.js',
|
||||
'assets/js/login.js',
|
||||
'assets/js/main.js',
|
||||
'assets/js/manage.js',
|
||||
'assets/js/map.js',
|
||||
'assets/js/map_leaflet.js',
|
||||
'assets/js/map_mapbox.js',
|
||||
'assets/js/notes.js',
|
||||
'assets/js/packages.js',
|
||||
'assets/js/platform.js',
|
||||
'assets/js/settings.js',
|
||||
'assets/js/storage.js',
|
||||
'assets/js/sync.js',
|
||||
'assets/js/toolbox_scannerentries.js',
|
||||
'assets/js/toolbox_scanner.js',
|
||||
'assets/js/toolbox_sharelist.js',
|
||||
'assets/js/toolbox_track.js',
|
||||
'assets/js/toolbox_weather.js',
|
||||
'assets/js/util.js',
|
||||
|
||||
'pages/credits.html',
|
||||
'pages/home.html',
|
||||
'pages/list.html',
|
||||
'pages/login.html',
|
||||
'pages/manage.html',
|
||||
'pages/map.html',
|
||||
'pages/myroute.html',
|
||||
'pages/settings.html',
|
||||
'pages/toolbox.html',
|
||||
'pages/help/list.html',
|
||||
'pages/help/map.html',
|
||||
'pages/myroute/editnote.html',
|
||||
'pages/toolbox/scanner.html',
|
||||
'pages/toolbox/sharelist.html',
|
||||
'pages/toolbox/track.html',
|
||||
'pages/toolbox/trackinginfo.html',
|
||||
'pages/toolbox/weather.html',
|
||||
'pages/toolbox/scanner/entries.html',
|
||||
'pages/toolbox/scanner/scanner.html',
|
||||
|
||||
'node_modules/framework7/css/framework7.bundle.min.css',
|
||||
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
|
||||
'node_modules/material-design-icons/iconfont/material-icons.css',
|
||||
'node_modules/leaflet/dist/leaflet.css',
|
||||
'node_modules/leaflet.markercluster/dist/MarkerCluster.css',
|
||||
'node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css',
|
||||
'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.css',
|
||||
'node_modules/mapbox-gl/dist/mapbox-gl.css',
|
||||
'node_modules/framework7/js/framework7.bundle.min.js',
|
||||
'node_modules/jquery/dist/jquery.min.js',
|
||||
'node_modules/leaflet/dist/leaflet.js',
|
||||
'node_modules/leaflet.markercluster/dist/leaflet.markercluster.js',
|
||||
'node_modules/mapbox-gl/dist/mapbox-gl.js',
|
||||
'node_modules/jsbarcode/dist/JsBarcode.all.min.js',
|
||||
'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.js',
|
||||
'node_modules/@zxing/library/umd/index.min.js',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.ttf',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.woff',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.woff2',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.ttf',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.woff',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.woff2',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.ttf',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.woff',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.woff2',
|
||||
'node_modules/material-design-icons/iconfont/MaterialIcons-Regular.ttf',
|
||||
'node_modules/material-design-icons/iconfont/MaterialIcons-Regular.woff',
|
||||
'node_modules/material-design-icons/iconfont/MaterialIcons-Regular.woff2'
|
||||
];
|
||||
|
||||
for (i in SETTINGS.maptileurls) {
|
||||
cachedurls.push(SETTINGS.maptileurls[i].json);
|
||||
}
|
||||
|
||||
for (i in SETTINGS.alertsounds) {
|
||||
cachedurls.push("assets/audio/" + SETTINGS.alertsounds[i].file);
|
||||
}
|
||||
|
||||
for (i in SETTINGS.weathericons) {
|
||||
cachedurls.push("assets/images/weather-" + SETTINGS.weathericons[i] + ".svg");
|
||||
}
|
||||
|
||||
function fillCache(cachename) {
|
||||
if ('caches' in window) {
|
||||
// delete old caches
|
||||
caches.keys().then(function (cacheNames) {
|
||||
return Promise.all(cacheNames.map(function (oldCacheName) {
|
||||
if (oldCacheName != cachename) {
|
||||
return caches.delete(oldCacheName);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
caches.open(cachename).then(function (cache) {
|
||||
for (i in cachedurls) {
|
||||
cache.add(cachedurls[i]);
|
||||
}
|
||||
});
|
||||
|
||||
// Do it again in a little while to reduce chance of errors
|
||||
setTimeout(function () {
|
||||
fillCache(cachename);
|
||||
}, 1000 * 30);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue