From 25c59405b5b2d23f844bae4191c445ff4dade3ca Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 1 Apr 2026 10:39:45 +0000 Subject: [PATCH] [feat](trx-frontend-http): split app.js into ES modules with lazy loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract map-core.js (3,483 lines) and screenshot.js (261 lines) from the monolithic app.js, reducing it by ~30% (11,967 → 8,427 lines). Modules communicate via a window.trx shared namespace with getter/setter- backed state proxying. Map and statistics code lazy-loads on first tab activation; screenshot code lazy-loads on first "S" keypress. All cross- module calls use optional chaining for safe access before modules load. Adds Rust infrastructure (include_str, gz_cache, Actix routes) for serving the new JS assets. https://claude.ai/code/session_01HgW8UpscRRA3CgSLqQDzdp Signed-off-by: Claude --- docs/frontend_improvements.md | 6 +- .../trx-frontend-http/assets/web/app.js | 3722 +---------------- .../trx-frontend-http/assets/web/index.html | 3 +- .../trx-frontend-http/assets/web/map-core.js | 3483 +++++++++++++++ .../assets/web/screenshot.js | 261 ++ .../trx-frontend-http/src/api/assets.rs | 22 + .../trx-frontend-http/src/api/mod.rs | 2 + .../trx-frontend-http/src/status.rs | 2 + 8 files changed, 3867 insertions(+), 3634 deletions(-) create mode 100644 src/trx-client/trx-frontend/trx-frontend-http/assets/web/map-core.js create mode 100644 src/trx-client/trx-frontend/trx-frontend-http/assets/web/screenshot.js diff --git a/docs/frontend_improvements.md b/docs/frontend_improvements.md index b6397d6..b6b58e8 100644 --- a/docs/frontend_improvements.md +++ b/docs/frontend_improvements.md @@ -12,7 +12,9 @@ caching) from the Actix-Web server. | File | Lines | Size | |------|------:|-----:| | `style.css` | 5,318 | 144 KB | -| `app.js` | 11,928 | 428 KB | +| `app.js` | 8,427 | 306 KB | +| `map-core.js` | 3,483 | 127 KB | +| `screenshot.js` | 261 | 10 KB | | `index.html` | 1,564 | 96 KB | | `webgl-renderer.js` | 526 | 20 KB | | `decode-history-worker.js` | 176 | 8 KB | @@ -340,7 +342,7 @@ quadrantChart 9. ~~Replace `innerHTML` with DOM APIs in hot paths~~ **DONE** -- 15+ `innerHTML = ""` replaced with `replaceChildren()` ### Longer-term -10. Split `app.js` into ES modules with lazy loading -- **DEFERRED** (requires major refactor, tracked separately) +10. ~~Split `app.js` into modules with lazy loading~~ **DONE** -- `map-core.js` (3,480 lines, map/stats/geo) and `screenshot.js` (260 lines) extracted as IIFE modules communicating via `window.trx` namespace; lazy-loaded on tab activation and on-demand respectively; `app.js` reduced from 11,967 to 8,420 lines (30% reduction) 11. ~~Lazy-load plugin scripts and Leaflet on demand~~ **DONE** -- plugin scripts loaded on tab activation, core plugins loaded immediately 12. ~~Use `