chore(client): tighten the precache ceiling and correct the offline docs (#1815)

* chore(client): tighten the precache ceiling now the entry chunk is split

The 6 MB ceiling was set against the pre-split bundle, where the entry chunk
alone was 5.2 MB. It is now 1.2 MB and the largest precached entry is the
heic-to chunk at 3.0 MB, so the old limit had nothing left to catch.

Worth being explicit about what the limit does: a file above it is dropped
from the manifest and the build still succeeds, printing only that the file
will not be precached. The PWA is then quietly broken offline for that file,
which is why the ceiling has to stay close to the real bundle.

Also records why every route chunk is precached rather than pulled in at
runtime, since that is the reason route splitting did not shrink the install.

* docs(wiki): correct the offline cache table

The table still described an api-data cache holding API responses for 24
hours under NetworkFirst. That cache is gone: API requests are NetworkOnly
because Workbox keys entries by URL and cannot vary them on the session
cookie, so on a shared device one account's data could be served to the next.
Documenting a cache that deliberately does not exist is the wrong way round
for a privacy decision.

Map tiles were listed at 1 000 entries; the actual cap is 12 288 and has to
stay in step with MAX_TILES in tilePrefetcher.ts. The two GL tile caches were
missing altogether, and the precache line now says that it covers every page
rather than just the shell.
This commit is contained in:
Maurice
2026-08-07 10:25:44 +02:00
committed by GitHub
parent 96e4ff5932
commit e5962c22d5
2 changed files with 18 additions and 9 deletions
+11 -5
View File
@@ -24,11 +24,17 @@ export default defineConfig(({ mode }) => ({
suppressWarnings: true,
},
workbox: {
// Anything above this is dropped from the precache manifest without failing
// the build, so the PWA would just be broken offline. Keep the ceiling close
// to the real bundle so growth shows up as a build warning instead. Revisit
// once route-level splitting lands and the entry chunk shrinks.
maximumFileSizeToCacheInBytes: 6 * 1024 * 1024,
// Anything above this is dropped from the precache manifest. The build does
// not fail over it, it only prints "won't be precached", so the ceiling has
// to sit close to the real bundle or an accidental heavyweight goes
// offline-broken unnoticed. Largest precached entry after route splitting is
// the heic-to chunk at 3.0 MB; the entry chunk is down to 1.2 MB.
maximumFileSizeToCacheInBytes: 3.5 * 1024 * 1024,
// Every route chunk is precached alongside the shell, deliberately: for an
// offline-first travel planner a route the user never opened before losing
// signal still has to work. The trade is that route splitting buys first
// paint and not install size — 107 entries / 17,795 KiB before the split,
// 178 / 17,826 KiB after.
globPatterns: ['**/*.{js,css,html,svg,png,woff,woff2,ttf}'],
// build:analyze drops a treemap next to the app; it must never end up in a
// precache manifest if someone ships that build by accident.
+7 -4
View File
@@ -26,12 +26,15 @@ TREK uses Workbox service-worker caching plus an IndexedDB database (Dexie) for
| Content | Cache name | Strategy | Duration | Max entries |
|---------|------------|----------|----------|-------------|
| CartoDB / OpenStreetMap map tiles | `map-tiles` | CacheFirst | 30 days | 1 000 |
| API responses (trips, places, bookings, etc.) | `api-data` | NetworkFirst (5 s timeout) | 24 hours | 200 |
| CartoDB / OpenStreetMap map tiles | `map-tiles` | CacheFirst | 30 days | 12 288 |
| Mapbox GL style, glyphs, sprites and vector tiles | `mapbox-tiles` | StaleWhileRevalidate | 30 days | 3 000 |
| OpenFreeMap MapLibre style and tiles | `openfreemap-tiles` | StaleWhileRevalidate | 30 days | 3 000 |
| Cover images and avatars (`/uploads/covers`, `/uploads/avatars`) | `user-uploads` | CacheFirst | 7 days | 300 |
| App shell (HTML / JS / CSS) | precache | Precached | Until next deploy | — |
| App shell and every page of the app (HTML / JS / CSS) | precache | Precached | Until next deploy | — |
> **Note:** The API cache excludes sensitive endpoints — `/api/auth`, `/api/admin`, `/api/backup`, and `/api/settings` are always fetched from the network.
> **Note:** API responses are **never** stored in the service-worker cache. Workbox keys its entries by URL and cannot vary them on the session cookie, so on a shared device one account's cached data could be served to the next. Offline reads come from the per-user IndexedDB cache described below instead.
> **Note:** The precache covers every page, not just the one you happen to open first. A page you have never visited still works after you lose connectivity — at the cost of a larger initial install.
**IndexedDB (Dexie) — structured trip data**