Skip to content

perf: omit app-webrtc.js from page load when WebRTC is disabled#552

Closed
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/webui-no-webrtc-script
Closed

perf: omit app-webrtc.js from page load when WebRTC is disabled#552
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/webui-no-webrtc-script

Conversation

@sam-saffron-jarvis
Copy link
Copy Markdown
Contributor

What

Omit app-webrtc.js from the page and service worker when WebRTC is not enabled.

  • Strip the <script src="app-webrtc.js?v=..."> tag from the rendered index.html
  • Remove './app-webrtc.js?v=...' from the service worker's SHELL_ASSETS list

WebRTC-enabled deployments (--webrtc flag / TERM_LLM_WEBRTC_* env) are unaffected — the script tag is preserved and the SW still precaches the asset.

Why

app-webrtc.js is 21 KB uncompressed (~6 KB gzip). It is an IIFE that checks window.__WEBRTC_ENABLED__ at startup and exits immediately when the flag is absent. Without the flag the entire file is dead code: the browser fetches it, parses it, executes it — and nothing happens.

For the vast majority of deployments (no --webrtc flag), this saves:

  • ~6 KB of network transfer per page load
  • JS parse + execute time for 21 KB of unused code (~10–15 ms on mid-range devices)
  • One network request during service worker install

Tests

  • TestRenderIndexHTML_DropsWebRTCScriptWhenDisabled — script tag absent when webrtcHeadSnippet is empty
  • TestRenderIndexHTML_KeepsWebRTCScriptWhenEnabled — script tag present when snippet is set
  • TestDropScriptTagContaining — helper removes correct tag, leaves others
  • TestDropScriptTagContaining_NeedleAbsent — no-op when needle not found
  • TestDropSWShellAssetContaining — removes webrtc entry from real rendered SW, other assets intact

app-webrtc.js (21 KB uncompressed, ~6 KB gzip) is an IIFE that only
activates when window.__WEBRTC_ENABLED__ is set. Without that flag the
entire script is dead code — it is parsed and executed but does nothing.

When webrtcHeadSnippet is empty (the default for all non-WebRTC
deployments):
 - strip the <script src="app-webrtc.js"> tag from the rendered HTML
 - remove the './app-webrtc.js?v=...' entry from the service worker's
   SHELL_ASSETS list so the SW does not precache the file on install

WebRTC-enabled deployments are unaffected: the script tag is kept and
the service worker still precaches the asset.

Adds unit tests for the two helpers and integration tests through
renderIndexHTML() confirming the tag is present/absent as expected.
@SamSaffron
Copy link
Copy Markdown
Owner

Closed in favor of a cleaner implementation that avoids parsing rendered HTML/JS and uses explicit serveui render options/placeholders instead.

@SamSaffron SamSaffron closed this May 8, 2026
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.

2 participants