Repository navigation
range-source-web 1.1.0
- A Service Worker for media elements.
<video>and<audio>make their own requests, so what they played skipped the reader and the store. The worker answers them: from the store first, fetching what's missing by range and storing it, so a file played through plays again with no requests, offline too.- The page registers it before rendering with
registerRangeSourceWorker('/range-source-sw.js'), which resolves once the worker controls the page (claiming it again after a hard reload), and gives elementsserviceWorkerUrl(src, { namespace, key, storage, maxBytes, headers }), a URL on the page's origin that the worker answers.rangeSourceWorker()tells whether one controls the page. - It sends the page's
headersfor the element, and plays aBlob, bytes or aByteSourcethe page holds, whose ranges the page reads and passes on. A file on another origin without CORS is passed through, unstored. - The package ships the worker as
dist/range-source-sw.js(exportrange-source-web/range-source-sw.js). An app with its own worker adds the handler fromrange-source-web/sw(installRangeSourceWorker,handleRangeSourceFetch) orimportScriptsthe script.
- The page registers it before rendering with
- Stores are shared between pages, tabs and the worker: blocks written and keys deleted are announced on a
BroadcastChannel, and a key open in any of them isn't evicted (Web Locks). SourceInfo.contentType, from the response'sContent-Typeor theBlob's type.httpSource'sopenAtoption: the first request starts there rather than at 0.ByteReader.stored(): resolves once the blocks read so far are in the store.npm run test:browsers: the worker in Chromium, Firefox and WebKit through Playwright.- The package includes this changelog.
Install: npm install range-source-web@1.1.0. Only range-source-web changed; the native packages stay at 1.0.0.