Skip to content

refactor: replace bcp-47-normalize with lightweight BCP-47 normalization (-185 KB)#4970

Open
PascalThuet wants to merge 2 commits intoDash-Industry-Forum:developmentfrom
PascalThuet:optim/a1-replace-bcp47-normalize
Open

refactor: replace bcp-47-normalize with lightweight BCP-47 normalization (-185 KB)#4970
PascalThuet wants to merge 2 commits intoDash-Industry-Forum:developmentfrom
PascalThuet:optim/a1-replace-bcp47-normalize

Conversation

@PascalThuet
Copy link
Contributor

Summary

  • Remove bcp-47-normalize dependency and its transitive deps (bcp-47, is-alphabetical, is-alphanumerical, is-decimal)
  • Replace with a ~75-line internal utility src/streaming/utils/BCP47Utils.js
  • -185,508 bytes on dash.all.min.js (-18.9%)

What changed

New file: src/streaming/utils/BCP47Utils.js

  • normalizeBcp47(tag): RFC 5646 case normalization (language → lowercase, script → titlecase, region → uppercase) + complete ISO 639-2/B and 639-2/T → ISO 639-1 lookup table (184 entries)

Modified files: replaced import {bcp47Normalize} from 'bcp-47-normalize' with import {normalizeBcp47} from '...BCP47Utils.js' in:

  • src/streaming/controllers/MediaController.js (2 call sites)
  • src/dash/parser/matchers/LangMatcher.js (1 call site)
  • src/dash/DashAdapter.js (1 call site)

package.json: removed bcp-47-normalize from dependencies. bcp-47-match (provides extendedFilter()) is unchanged.

Bundle size

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

Before After 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%)

What is NOT covered

The full bcp-47-normalize also handles features dash.js never uses:

  • Deprecated language aliases (iwhe, inid): rare in real MPDs. A small table could be added later if needed.
  • Likely subtag expansion (zhzh-Hans-CN): unnecessary because extendedFilter() already matches via RFC 4647 prefix matching.

Test plan

  • All 3,332 unit tests pass without modification
  • Tests exercising ISO 639-2 codes pass (spaes, frefr)
  • Manual: VOD playback with audio language selection
  • Manual: Content with CEA-608 captions

Fixes #4969

Copilot AI review requested due to automatic review settings March 1, 2026 14:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the heavyweight bcp-47-normalize dependency and replaces it with a small internal BCP-47 normalization utility to reduce the shipped bundle size, while keeping the language-tag normalization behavior needed by dash.js.

Changes:

  • Added normalizeBcp47() utility with RFC 5646 case normalization + ISO 639-2 → 639-1 mapping.
  • Updated DASH parsing/selection code paths to use normalizeBcp47() instead of bcp47Normalize().
  • Removed bcp-47-normalize from package.json dependencies.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/streaming/utils/BCP47Utils.js Introduces internal BCP-47 normalization + ISO 639-2→1 mapping table.
src/streaming/controllers/MediaController.js Switches language matching normalization to the new internal utility.
src/dash/parser/matchers/LangMatcher.js Switches MPD lang attribute normalization to the new internal utility.
src/dash/DashAdapter.js Switches CEA-608 caption language normalization to the new internal utility.
package.json Removes the bcp-47-normalize dependency entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Remove the bcp-47-normalize dependency (~185 KB minified including
transitive deps) and replace it with a ~75-line internal utility that
covers the two features dash.js actually uses: RFC 5646 case
normalization and ISO 639-2 to 639-1 conversion.

Fixes Dash-Industry-Forum#4969
@PascalThuet PascalThuet force-pushed the optim/a1-replace-bcp47-normalize branch from 716b1cc to d0b9192 Compare March 1, 2026 14:21
- Add standard dash.js BSD license header to BCP47Utils.js
- Use Object.create(null) for ISO_639_2_TO_1 to prevent prototype pollution
- Regenerate package-lock.json to remove bcp-47-normalize and transitive deps
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.

Reduce bundle size: replace bcp-47-normalize dependency (-185 KB / -19%)

2 participants