Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read the ZIM file directly from the ServiceWorker #853

Open
mossroy opened this issue Apr 8, 2022 · 2 comments
Open

Read the ZIM file directly from the ServiceWorker #853

mossroy opened this issue Apr 8, 2022 · 2 comments
Assignees
Milestone

Comments

@mossroy
Copy link
Contributor

mossroy commented Apr 8, 2022

So far, it was impossible for a ServiceWorker to read the ZIM file directly.
So we setup a MessageChannel with the main javascript thread, transfer the "request" to the main thread, which reads the ZIM file, and transfers the content back to the ServiceWorker.

When discussing in kiwix/libkiwix#740, I discovered that recent browsers can now transfer a https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream, and that we can get such a ReadableStream from our File object: https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream

It means that we might be able to transfer the ZIM files (as ReadableStreams) to the ServiceWorker. So that the ServiceWorker would be able to directly make use of our "backend" to read the ZIM.

Unfortunately, this will only work with recent versions of browser engines. We'll have to keep the current MessageChannel logic for older ones (at least IE11, Firefox OS, Windows Mobile, maybe Ubuntu Touch).

But this might improve performance, and might also allow to make use of bigger parts of the C libraries, like considered in kiwix/libkiwix#740

@mossroy mossroy added this to the v3.5 milestone Apr 8, 2022
@mossroy mossroy self-assigned this Apr 8, 2022
@mossroy
Copy link
Contributor Author

mossroy commented Apr 8, 2022

Regarding the webassembly backend, it might be possible to use it from the ServiceWorker, too: https://medium.com/@kennethrohde/on-the-fly-webp-decoding-using-wasm-and-a-service-worker-33e519d8c21e (needs to be tested)

@mossroy
Copy link
Contributor Author

mossroy commented Apr 9, 2022

In fact, the old browsers (IE etc) I was mentioning above don't support ServiceWorkers anyway (except maybe Ubuntu Touch).

But, if we manage to use this technique, the MessageChannel would need to be kept for some browser versions anyway:

  • Chrome 40 to 75
  • Edge 17 to 78
  • Firefox 44 to 68
  • and same for other browsers

Except if we cleanly fallback to jQuery mode for them (but it would be a more important feature loss)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants