Skip to content

Reduce bundle size: replace ua-parser-js dependency (-26 KB / -2.6%) #4971

@PascalThuet

Description

@PascalThuet

Description

ua-parser-js adds 25.8 KB to the minified modern bundle (dash.all.min.js). The package is a full-featured User-Agent parser that detects browser, OS, device, CPU, and rendering engine.

dash.js uses it in one utility method (Utils.parseUserAgent()), called from 2 locations, both of which only read ua.browser.name:

File Line Usage
CatchupController.js 125 ua.browser.name === 'safari' — Safari detection for live catchup behavior
ProtectionController.js 1491 ua.browser.name === 'edge' — Edge detection for a PlayReady DRM workaround

None of the other ua-parser-js capabilities (OS, device, CPU, engine detection) are used anywhere in dash.js source code. The parseUserAgent method is not part of the public API.

Solution

Replace the ua-parser-js import with a lightweight regex-based browser detection directly in Utils.parseUserAgent(). The two consumers only need Safari and Edge detection, which can be done with simple regex tests on navigator.userAgent.

The return type ({ browser: { name: string } }) stays identical so the two call sites don't need to change.

Measured on development branch (v5.2.0), modern prod build:

Current After removal Diff
dash.all.min.js 983,658 B 957,803 B -25,855 B (-2.6%)
dash.all.debug.js 3,503,300 B 3,431,577 B -71,723 B (-2.0%)

Alternatives

  • Keep ua-parser-js as-is: no risk, but 25.8 KB of unused parsing capability stays in the bundle.
  • Lazy-load ua-parser-js: possible, but adds complexity for a dependency that can be trivially replaced. CatchupController calls parseUserAgent() at initialization, so lazy-loading would complicate startup.
  • Use navigator.userAgentData (UA-CH API): modern API but not available on Smart TVs or older browsers. Would still need a regex fallback.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions