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

Switch to ServiceWorker mode by default #196

Closed
mossroy opened this issue Apr 5, 2017 · 17 comments
Closed

Switch to ServiceWorker mode by default #196

mossroy opened this issue Apr 5, 2017 · 17 comments
Assignees
Milestone

Comments

@mossroy
Copy link
Contributor

mossroy commented Apr 5, 2017

The ServiceWorker mode is faster and cleaner.
At startup, we should first try to enable it by default (except if the user has chosen jQuery mode before).
If it fails, we fallback to jQuery mode.

@mossroy mossroy self-assigned this Apr 5, 2017
@mossroy mossroy modified the milestones: v2.0, v2.1 Apr 5, 2017
@sharun-s
Copy link
Contributor

It would be great if you could add some more detail on the difference between these two modes? I think it will help future contributors to get a better idea of the code and why they exist. Right now given the two different formats zim/evo archive, two different content injection modes (probably a third coming with webrequest), the weird zim format(whose advantages aren't clear), references to firefox os/geo location etc the barrier to entry for a dev to figure out what is going on is a bit high.

I think this is a fantastic project with lot of potential for all kinds of offline use-cases and I feel you will get more devs involved and exploring those use cases, if the core pieces of this project are well documented. Thanks for all the work you guys do!

@mossroy
Copy link
Contributor Author

mossroy commented Apr 22, 2017

Thanks for your feedback @sharun-s
I think what you mentioned is not only related to jQuery & ServiceWorker modes, so I created #218 to discuss all this. I'll answer in this new issue

@mossroy mossroy modified the milestones: v2.3, v2.2 Jul 25, 2017
@Jaifroid
Copy link
Member

Jaifroid commented Jun 2, 2018

In #383 @mossroy wrote:

Regarding the ServiceWorker mode in general, there are many things that should be easier and faster to achieve with it, using the browser capabilities instead of reimplementing things ourself. That's why I'm willing to focus on it for the next hackathon, in order to (hopefully) make it the default mode (when available on the device/browser). It does not mean we would drop jQuery mode support, because it's still necessary in many contexts.

I agree that the Service Worker approach is cleaner, and the logical way to do things. Effectively, we've written an emulation of ServiceWorker in jQuery, which is quite high maintenance. However, I perceive a number of issues with Service Worker still:

  • Firefox (even Quantum) still has not (seemingly) enable Service Worker mode as standard. Running Firefox from localhost, on Windows, I am unable to use Service Worker. Perhaps https: is required? Edge and Chromium now work out of the box, running from localhost in http: ;

  • No browser allows Service Workers under the file:// protocol. This does not affect browser extensions, of course. But I've always felt that a major advantage of Kiwix JS is that you can simply run it by clicking on index.html. In fact, I've always thought of this as the major flexibility and use-case for the app. The simplicity of being able to distribute an offline ZIM reader, with a ZIM, on, say, a thumb drive, is a major advantage of Kiwix JS. We cannot expect users to have servers installed on their machines. I realize this advantage fails with Chrome.

  • A minor consideration: while Service Workers now work without flags in Edge, they have not yet been ported to UWP. However, this will come soon for Windows 10. It won't, unfortunately, be backported to Windows Mobile. Any future mobile devices (including tablets and small PDA-style devices) from Microsoft and other manufacturers will run Windows on ARM (which is full Windows 10). It will have Service Worker. But current mobile devices will not get the backport or be upgradeable without hacking, sadly.

@mossroy
Copy link
Contributor Author

mossroy commented Jun 3, 2018

Firefox has implemented Service Workers, and it works for me when running from localhost (without https). They are however disabled in ESR versions (so far) : Firefox 52 ESR and Firefox 60 ESR. Please check you're not using an ESR version.
Please check also in about:config that the dom.serviceWorkers.enabled property is set to true.

https should be required for Service Workers only when the host is distant (not from localhost)

But, for now, Firefox disables Service Workers inside a browser extension. I've asked to enable them in https://bugzilla.mozilla.org/show_bug.cgi?id=1344561 : they first answered no, but finally answered yes (but they currently have no timeline for doing it)

Service Workers are disabled under the file:// protocol. It's true that it's at least annoying for development. But I'm not sure double-clicking on index.html is the major use case. IMHO, major use-cases are currently running as an app on mobile and other non-desktop platforms (Windows, FFOS, Ubuntu Touch, maybe other ones), and running as a browser extension. I'm not sure for UWP and Ubuntu touch apps, but the other contexts do not use file:// protocol. In any case, it's something we might ask to the browsers vendors, because I don't see the security threat (provided that the Service Worker only traps requests from its own content to its own content)

It's true that Service Workers are not usable in all contexts. That's why we need to keep the jQuery mode as a fallback.
But I feel the need to put more focus on this ServiceWorker mode now, as it is IMHO the way to go for the future.
I'll try to fix the stability issues of our implementation (#145), so that to be able to make it the default mode (when available)

@Jaifroid
Copy link
Member

Jaifroid commented Jun 3, 2018

Apologies, yes, Service Worker is now working for me on Firefox Quantum in localhost. what happens is that sometimes I've been using the ESR version of Firefox, and then when I open the Quantum profile it nevertheless loads up ESR, probably because ESR hasn't fully exited, and that confused me.

Your strategy seems good to me. I think so long as a version is still available that works without SW in the medium term, it'll be fine to initiate a pivot towards SW. UWP works in app context, not in file: context, so Service Workers will work if targeting the latest SDK (but I can't do that because of mobile).

@mossroy
Copy link
Contributor Author

mossroy commented Sep 9, 2019

Maybe it is time to implement this, now that #556 has been merged?
The only drawback I can see is #404 but maybe it's not a blocker.

@Jaifroid
Copy link
Member

I would be happy to see this implemented, assuming the device would silently fall back to jQuery mode if SW is not implemented on first startup. Thereafter, if a user attempts to switch to SW mode on a non-supported device, they would receive an explicit error message explaining why not. Regarding #404, I can fix it for you with one line of code, but you won't like the solution (!). I don't think #404 is a blocker, but it is poor UX. However, it should be discussed further there.

Are you happy to implement this issue? (I'm travelling and away from my dev machine for the next week.)

@mossroy
Copy link
Contributor Author

mossroy commented Sep 10, 2019

I agree. The idea is to use SW mode (by default) on platforms that support it, and automatically fallback to jQuery mode (by default) where it's not.
And we should still let the user manually choose the mode (kept in a cookie).
I propose to use another cookie name, so that, when upgrading kiwix-js (only once), we ignore the previous choice of the user (from previous versions where the SW was not great), and switch to the default one : SW if available, jQuery if it's not.

Yes, I can implement it (it is already assigned to me). But I probably won't be able to do that in the near future. I have many things to do (aside from kiwix-js) that will let me very little availability to actually develop, until the end of January 2020.
If you want to implement it by yourself, please do, but don't feel forced to.

@mossroy mossroy modified the milestones: v2.7, v2.8 Mar 29, 2020
@mossroy mossroy removed this from the v2.8 milestone Jul 11, 2020
@kelson42
Copy link
Collaborator

kelson42 commented May 8, 2022

#732 is in milestone 3.6 which makes it impossible to implement this ticket in 3.5 milestone.

@Jaifroid
Copy link
Member

Jaifroid commented Jun 2, 2022

@kelson42 @mossroy I just saw the discussion of this on Slack. I don't think #732 is a blocker at all. It was more a desirable thing at some point. It can be removed from this list.

@mossroy
Copy link
Contributor Author

mossroy commented Jun 2, 2022

I've updated the list of prerequisites to remove #732 but add #531

@mossroy mossroy modified the milestones: v3.5, v3.6 Aug 4, 2022
@mossroy
Copy link
Contributor Author

mossroy commented Aug 6, 2022

I've started to work a bit on that. I've created a new branch "Switch-to-SW-mode-by-default", but it's still a work-in-progress

@Jaifroid
Copy link
Member

@mossroy Can I (or you if you wish) rebase that branch "Switch-to-SW-mode-by-default" on master and then open a PR? I think it would be good to list the steps that need to be completed. In principle, I don't think it's complicated, as the PWA version (moz-extension.kiwix.org) already starts in SW mode by default, but maybe there are some complications we need to take into account, or fallbacks/tests we need to put in place.

@Jaifroid
Copy link
Member

PS I only ask because you started that work.

@mossroy
Copy link
Contributor Author

mossroy commented Oct 15, 2022

Sure, you can.
It was still a work-in-progress.

It should not be very complicated, but is not really straight-forward either.
There are indeed many different uses-cases to handle (and test). Here is what I thought about (open to discuss), and started to implement:

  • new user/installation with SW supported: use SW (but warn about the switch to PWA for Firefox)
  • new user/installation but SW unsupported: fallback to jQuery mode with a one-time warning
  • existing installation with SW mode selected: keep SW
  • existing installation with jQuery mode and SW supported: we should switch to SW mode with a one-time information (but warn about the switch to PWA for Firefox)
  • existing installation with jQuery mode but SW unsupported: we should stay in jQuery mode with a one-time warning

The case of old Firefox browsers with no SW support should be tested, just to check the UX is not too awful, without spending too much time on them (remember what we wrote in 53ba099#diff-484c9e8aa09e09b8eb1fafaf55e8eadcd0eaab230e38d02bb9440841bfa090a4R786)

@mossroy
Copy link
Contributor Author

mossroy commented Oct 16, 2022

Forgot to mention that all these use-cases are only relevant if we want to keep the very broad compatibility we kept since today

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

4 participants