[HTML5] PWA service worker prefers cached version.

Use an offline first approach, where we prefer the cached version over
the network one.
This forces games using PWA to always re-export the project and not just
the PCK, so that the service worker version gets updated correctly, and
the end-user cache is correctly cleared on update.
This commit is contained in:
Fabio Alessandrelli 2021-12-21 14:41:26 +01:00
parent 95719930a8
commit cc4612277b
4 changed files with 112 additions and 63 deletions

View file

@ -106,6 +106,13 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
* @default
*/
experimentalVK: false,
/**
* The progressive web app service worker to install.
* @memberof EngineConfig
* @default
* @type {string}
*/
serviceWorker: '',
/**
* @ignore
* @type {Array.<string>}
@ -249,6 +256,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
this.persistentDrops = parse('persistentDrops', this.persistentDrops);
this.experimentalVK = parse('experimentalVK', this.experimentalVK);
this.focusCanvas = parse('focusCanvas', this.focusCanvas);
this.serviceWorker = parse('serviceWorker', this.serviceWorker);
this.gdnativeLibs = parse('gdnativeLibs', this.gdnativeLibs);
this.fileSizes = parse('fileSizes', this.fileSizes);
this.args = parse('args', this.args);

View file

@ -189,6 +189,9 @@ const Engine = (function () {
preloader.preloadedFiles.length = 0; // Clear memory
me.rtenv['callMain'](me.config.args);
initPromise = null;
if (me.config.serviceWorker && 'serviceWorker' in navigator) {
navigator.serviceWorker.register(me.config.serviceWorker);
}
resolve();
});
});