[Reference implementation] Service worker has no update functionality
The service worker currently does not have functionality for updating when the source files have changed, and it also does not clean up files that are no longer needed (files present in the cache but not in filesToCache array).
Implemented this in my project on this commit.
Feel free to take inspiration and use code snippets if it helps implementing this feature in eframe_template.
Key features
Auto-update with custom modal inside egui
Dynamic progress status and error display in HTML
Uses the trunk initializer feature.
No web_sys required to remove loading text
Implementation
Service worker changes
Custom trunk hook is used to create an unique sw.js file.
The browser detects updates by checking if the registered service worker changed on the origin. By inserting something like the build timestamp at build time, we generate an unique file every time.
This is then used to clear out any stale caches.
HTML page changes
Added JS that takes care of reacting to the browser's built in update check and then tells the result to the Rust side using wasm_bindgen.
JavaScript side (this later calls into Rust code)
Rust side (this value is then later checked in the UI code)
Why did I not submit a PR?
The issue is that my implementation is very specialized towards my app and I dont really know how to make a generalized implementation that would work for any project or fit the style guide / expected code architecture. It is also not very future proof as you might want to pass more data (like the load time for example) to the Rust side upon project load, but my impl currently only has a single static AtomicBool representing whether an update is available.