Use manual pre-caching for better HTTP cache busting

Former-commit-id: b966a1e5967dfd66e4c9e83fdf0e61d5d7d0717e [formerly 3d43f91aeac1a4c77dc0fbfdf0db521e276d6ee9 [formerly b9bb84a9fbd23c24a47e6701e82011170e36cf9d]]
Former-commit-id: 6acd9c13f962bf3cb6fdaa688564284e014b1f49
Former-commit-id: b7d8a59316ac338a93d7b9fa2a428531f963cd20
This commit is contained in:
Jaifroid 2021-01-11 22:57:17 +00:00
parent 3d1d09f404
commit 81c8b9b97d
2 changed files with 14 additions and 6 deletions

View File

@ -4,7 +4,7 @@
// App version number - ENSURE IT MATCHES VALUE IN init.js // App version number - ENSURE IT MATCHES VALUE IN init.js
// DEV: Changing this will cause the browser to recognize that the Service Worker has changed, and it will download and // DEV: Changing this will cause the browser to recognize that the Service Worker has changed, and it will download and
// install a new copy // install a new copy
const appVersion = '1.1.4-RP1'; const appVersion = '1.1.4-RP2';
// Kiwix ZIM Archive Download Server in regex form // Kiwix ZIM Archive Download Server in regex form
// DEV: The server URL is defined in init.js, but is not available to us in SW // DEV: The server URL is defined in init.js, but is not available to us in SW
@ -57,6 +57,7 @@ const precacheFiles = [
"www/img/icons/map_marker-18px.png", "www/img/icons/map_marker-18px.png",
"www/img/spinner.gif", "www/img/spinner.gif",
"www/index.html", "www/index.html",
"www/article.html",
"www/js/app.js", "www/js/app.js",
"www/js/init.js", "www/js/init.js",
"www/js/lib/bootstrap.js", "www/js/lib/bootstrap.js",
@ -106,10 +107,17 @@ self.addEventListener("install", function (event) {
}); });
if (!excludedURLSchema.test(requests[0].url)) event.waitUntil( if (!excludedURLSchema.test(requests[0].url)) event.waitUntil(
caches.open(CACHE).then(function (cache) { caches.open(CACHE).then(function (cache) {
console.log("[SW] Caching pages during install"); return Promise.all(
return cache.addAll(requests).then().catch(function(err) { requests.map(function (request) {
console.error('There was an error precaching the app because', err); return fetch(request).then(function (response) {
}); // Fail on 404, 500 etc
if (!response.ok) throw Error('Could not fetch ' + request.url);
return cache.put(request.url.replace(/\?v[^?/]+$/, ''), response);
}).catch(function (err) {
console.error("There was an error pre-caching files", err);
});
})
);
}) })
); );
}); });

View File

@ -49,7 +49,7 @@ var params = {};
*/ */
var appstate = {}; var appstate = {};
/******** UPDATE VERSION IN pwabuilder-sw.js TO MATCH VERSION *******/ /******** UPDATE VERSION IN pwabuilder-sw.js TO MATCH VERSION *******/
params['version'] = "1.1.4-RP1"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js params['version'] = "1.1.4-RP2"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js
/******* UPDATE THIS ^^^^^^ IN serveice worker!! ********************/ /******* UPDATE THIS ^^^^^^ IN serveice worker!! ********************/
params['packagedFile'] = "wikipedia_en_100_maxi.zim"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage params['packagedFile'] = "wikipedia_en_100_maxi.zim"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage
params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory) params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory)