From bde0b95e27f118844279e360d3d87ae6f21e11f9 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 7 Oct 2022 18:53:39 +0200 Subject: [PATCH] Deprecate manual brotli decompression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It doesn't have much benefit but comes with a maintenance cost as we either need to keep patching upstream's js implementation for use in JSO — which also bloats binary size by including two copies of brotli and its default dict — or use the C implemntation from JS which requires boilerplate in both C and JS and also additional JS polyfills to keep e.g. the fontname extraction working. The browser's in-built support for Content-Encoding is more felxible, faster and simpler to use. Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/e459c8e6ffa83f2244f9745f54c39a19edd9684f --- README.md | 15 ++++++++++----- src/pre-worker.js | 8 +++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a8fa2191..d60906ca 100644 --- a/README.md +++ b/README.md @@ -195,11 +195,16 @@ Adjusting `prescaleFactor`, `prescaleHeightLimit` and `maxRenderHeight` to lower the rendering canvas can work around this at the expense of visual quality. -### Brotli Compressed Subtitles -The SubtitleOctopus allow the use of compressed subtitles in brotli format, -saving bandwidth and reducing library startup time - -To use, just run: `brotli subFile.ass` and use the .br result file with the subUrl option +### Brotli Compressed Subtitles (DEPRECATED) +Manual support for brotli-compressed subtitles is tentatively deprecated +and may be removed with the next release. + +Instead use HTTP's `Content-Encoding:` header to transmit files compressed and +let the browser handle decompression before it reaches JSO. This supports more +compression algorithms and is likely faster. +Do not use a `.br` file extension if you use `Content-Ecoding:` as this will +conflict with the still existing manual support which tries to decompress any data +with a `.br` extension. ## How to build? diff --git a/src/pre-worker.js b/src/pre-worker.js index abd2bc24..d805a224 100644 --- a/src/pre-worker.js +++ b/src/pre-worker.js @@ -45,7 +45,13 @@ function isBrotliFile(url) { len = url.length; } - return url.endsWith(".br", len); + if (url.endsWith(".br", len)) { + console.warn("Support for manual brotli decompression is tentatively deprecated and " + + "may be removed with the next release. Instead use HTTP's Content-Encoding.") + return true; + } + + return false; } Module = Module || {};