dash.js

Open Source Media Player

Seamless and reliable DASH streaming on any browser-based device

View onGitHub
5498
1728

Sponsors

Trusted by the industry leaders

Latest updates from GitHub

Reduce bundle size: replace ua-parser-js dependency (-26 KB / -2.6%)**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.Opened by PascalThuet2 days ago
Reduce bundle size: replace bcp-47-normalize dependency (-185 KB / -19%)**Problem description** `bcp-47-normalize` and its transitive dependencies (`bcp-47`, `is-alphabetical`, `is-alphanumerical`, `is-decimal`) add **185 KB** to the minified modern bundle — **19% of `dash.all.min.js`** (983 KB). The package carries a full IANA subtag registry (8,039 entries), 1,858 deprecated language code mappings, and 100+ deprecated region replacements. dash.js uses **one function** from this package, in **3 files**, for basic language tag case normalization and ISO 639-2 → 639-1 conversion before RFC 4647 matching. On Smart TV platforms (Tizen, WebOS, FireOS) with slow CPUs, 185 KB of unnecessary JavaScript directly impacts startup time. **Proposed solution** Replace `bcp-47-normalize` with a lightweight internal utility (~75 lines) that covers the two features dash.js actually uses: 1. Case normalization per RFC 5646 §2.1.1 (language → lowercase, script → titlecase, region → uppercase) 2. ISO 639-2 → 639-1 conversion (`fre` → `fr`, `spa` → `es`) via a standard lookup table (184 entries) `bcp-47-match` (12 KB, provides `extendedFilter()`) is a separate package with no shared code and would remain unchanged. Measured on `development` branch (v5.2.0), modern prod build: | | Current | After removal | Diff | |---|---------|---------------|------| | `dash.all.min.js` | 983,658 B | 798,150 B | **-185,508 B (-18.9%)** | | `dash.all.debug.js` | 3,503,300 B | 3,245,971 B | **-257,329 B (-7.3%)** | All 3,332 existing unit tests pass without modification. **Considered alternatives** - **Keep `bcp-47-normalize` as-is**: no risk, but 185 KB of dead code stays in the bundle. - **Minimal replacement (case normalization only, no ISO 639-2 table)**: smaller code, but breaks on MPDs that use 3-letter language codes like `spa` or `fre` — which existing tests confirm do occur. - **Use the full 414 mappings from `bcp-47-normalize`'s `matches.js`**: would also cover deprecated codes like `iw` → `he`, but adds complexity for codes that are extremely rare in real-world MPDs. Could be added later if needed. **Additional context** The 3 call sites that use `bcp47Normalize()`: | File | Usage | |------|-------| | `MediaController.js` (2 calls) | Normalizes `settings.lang` before `extendedFilter()` | | `LangMatcher.js` (1 call) | Normalizes `lang` attributes parsed from MPD | | `DashAdapter.js` (1 call) | Normalizes CEA-608 caption language | Features of `bcp-47-normalize` that dash.js never uses: - IANA likely subtag expansion (`zh` → `zh-Hans-CN`) — unnecessary because `extendedFilter()` already matches via RFC 4647 prefix matching - Deprecated code canonicalization (`iw` → `he`, `in` → `id`) - `Options.forgiving` and `Options.warning` callback Opened by PascalThuet2 days ago
Stylize subtitles, add them to your blockI tried a bunch of listeners, but nothing worked. ``` this.dsh.on(dashjs.MediaPlayer.events.TRACK_CHANGE_RENDERED, (e) => { }); ``` How is it possible to create your own html block and translate subtitles into it?Opened by Zuldek19948229 days ago

More news on

Contributors