Skip to content

perf(web): drop install icons from the precache and minify theme-init.js - #1323

Open
mforce wants to merge 1 commit into
mainfrom
perf/1322-precache-savings
Open

mforce wants to merge 1 commit into
mainfrom
perf/1322-precache-savings

Conversation

@mforce

@mforce mforce commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Refs #1322

The service worker precache drops from 1,677.86 KiB to 1,644.33 KiB (33.53 KiB less). PRECACHE_CEILING_KIB goes down from 1,680 to 1,659, which leaves 14.67 KiB of headroom.

What changed

Both changes are in web/vite.config.ts. web/scripts/verify-sw.mjs only gets the new ceiling and a history entry.

  1. The five install icons (icon-*.png, apple-touch-icon.png) are added to globIgnores, which saves 30.73 KiB. The browser downloads them from the manifest when someone installs the app, and that happens online. They are still in dist and are still served. includeManifestIcons: false stays, because the plugin would otherwise add them back. Its old comment said Workbox precaches the icons anyway, so I rewrote it.
  2. A new minifyThemeInit() plugin minifies dist/theme-init.js at build time, from 3,754 to 895 bytes. public/theme-init.js stays readable. The plugin uses writeBundle, which runs before the PWA plugin's closeBundle, so the precache revision is the hash of the minified file. The script is minified as a classic script, not a module, so its top-level vars are still globals, exactly as before. The URL (/theme-init.js) and the CSP do not change.

Verification

  • The theme-init.js revision in dist/sw.js equals the MD5 of dist/theme-init.js.
  • node scripts/verify-sw.mjs dist passes, reporting 1,644.33 KiB against the 1,659 KiB ceiling. I measured main (884b971) at 1,677.86 KiB on the same machine.
  • node --test scripts/*.test.mjs passes 19/19. The opticalSize, themeInit and theme Vitest files pass 42/42, and npm run typecheck is clean.
  • I also ran themeInit.test.ts once against the minified dist file. All 19 behavior tests passed. Only the slug-pattern parity test failed, which is expected because it compares source text.

Not in this PR

No screenshots: nothing a user sees changes.

The five install icons leave the Workbox precache; the browser fetches
them from the manifest at install time. theme-init.js is minified in
dist at build, so the precache revision hashes the minified bytes.

Precache: 1,677.86 KiB on main, 1,644.33 KiB on this branch. The
ceiling drops from 1,680 KiB to 1,659 KiB.

Refs #1322
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant