Improve handling of loading newly retrieved config.json
Currently when a new config.json
is available, one of these things happens:
- If it does not include configuration for plugins that have not been loaded with the service worker, it gets cached and applied next time the service worker is restarted.
- If it does include configuration for such plugins, and the
config.json
itself was retrieved using thefetch
plugin, assumption is made that the original website is available and the service worker is unregistered, triggering a clean re-registration (with the additional plugin scripts). - If it does include configuration for such plugins, and the
config.json
itself was not retrieved using thefetch
plugin, it cannot be assumed that the original website is up, and that the service worker and plugin scripts could be successfully fetched upon re-registration; at the same time,config.json
was in fact successfully retrieved, so clearly the old configuration works; therefore, the new config is discarded.
Potential ways to improve the situation:
- re: 1., 2. - check if there is a more graceful way for service worker re-registration (current implementation sometimes ends in a flash of an error page);
- re: 3. - check if it is possible to pre-cache the service worker script and the necessary plugins using other means than
fetch
, and then reliably re-register the service worker (relevant:updateViaCache
); - consider providing the visitor with the agency on when to re-register the service worker;
- consider implementing a
preloadPlugins
field inconfig.json
for plugins that are not used directly in the given configuration, but are preloaded (usingimportScripts()
) in the service worker so that they can be used whenconfig.json
changes.
Useful deep dive into service worker upgrade options (a tiny bit out of date perhaps):
https://redfin.engineering/how-to-fix-the-refresh-button-when-using-service-workers-a8e27af6df68?gif=true
Some more useful links:
Edited by Michał "rysiek" Woźniak