pandaxtc / towa

A web-based viewer for DeepZoom (.dzi) images.
MIT License
8 stars 3 forks source link

Can it use service worker instead of forking openseadragron #4

Closed sep2 closed 3 years ago

sep2 commented 3 years ago

Hi! Thanks for the great tool!

I don't really know how it works, but just wonder if you can use service worker to rewrite deep zoom request url to local filesystem, so that don't have to maintain a seperate openseadragron fork. Is it possible?

pandaxtc commented 3 years ago

Thank you for the suggestion! It definitely seems possible. I'll look into it and see what I can figure out.

pandaxtc commented 3 years ago

@sep2 I've looked into it, and though my understanding is pretty limited, I think the fact that service workers have an inherently unpredictable lifetime makes them unsuitable for this purpose. A service worker would be required to serve images from the filesystem, but the user agent can terminate them at any time. Please correct me if I'm wrong!

sep2 commented 3 years ago

not an expert either, so I would just quote from the docs

It's terminated when not in use, and restarted when it's next needed, so you cannot rely on global state within a service worker's onfetch and onmessage handlers. If there is information that you need to persist and reuse across restarts, service workers do have access to the IndexedDB API.

Anyway, thank you for your time!