From 51bb85fb9c4b1863d50a988598d82e7cbdc77b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Kraso=C5=84?= Date: Mon, 16 Dec 2024 18:21:09 +0100 Subject: [PATCH] fix PWA asset paths (#168) I noticed that app shell isn't correctly cached by the service worker. Consequently PWA doesn't start correctly. **Steps to reproduce** - Build and serve the app: `trunk serve` - Open app in the browser (chromium) - Click "Install egui Template PWA" - Close PWA - Stop the server (trunk) - Start previously installed PWA **Proposed solution** 1. trunkrs adds hashes to the file names: `eframe_template-*`. This makes paths in `sw.js` under `filesToCache` invalid. I solved it by adding `filehash = false`. The other option could be generating `sw.js` with correct filenames in `post_build` hook of trunkrs. 2. I noticed that when `manifest.json` is served from `assets/`, then installed PWA starts from attempting to read `assets/index.html` from cache. The file is non-existing, so startup fails. I solved it by moving `manifest.json` to the root directory. This required relative paths in `manifest.json` to be updated. --- Trunk.toml | 1 + assets/manifest.json | 6 +++--- index.html | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Trunk.toml b/Trunk.toml index a7b19c97..bd6c484b 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -1 +1,2 @@ [build] +filehash = false diff --git a/assets/manifest.json b/assets/manifest.json index 2a137fbc..5d6a9088 100644 --- a/assets/manifest.json +++ b/assets/manifest.json @@ -3,18 +3,18 @@ "short_name": "egui-template-pwa", "icons": [ { - "src": "./icon-256.png", + "src": "./assets/icon-256.png", "sizes": "256x256", "type": "image/png" }, { - "src": "./maskable_icon_x512.png", + "src": "./assets/maskable_icon_x512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" }, { - "src": "./icon-1024.png", + "src": "./assets/icon-1024.png", "sizes": "1024x1024", "type": "image/png" } diff --git a/index.html b/index.html index f1657ca9..c60e235f 100644 --- a/index.html +++ b/index.html @@ -18,14 +18,14 @@ - + - +