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 a Service Worker #774

Closed
j-f1 opened this issue Mar 25, 2018 · 22 comments
Closed

Switch to a Service Worker #774

j-f1 opened this issue Mar 25, 2018 · 22 comments
Labels

Comments

@j-f1
Copy link
Contributor

j-f1 commented Mar 25, 2018

It looks like Service Workers are supported on the latest versions of all of the browsers.

Some ideas:

  • automatically cache anything the user looks at while online
  • use Web Push to update docsets in the background even if DevDocs isn’t open (maybe if they disable auto-updates, we could prompt them with a desktop notification)
  • preload linked pages when the user tabs to a link to them, or hovers over the link
  • preload the top few search results for instant loading

If we use Service Workers, we won’t have to do anything different when offline vs online — just fetch the docset from the URL, and the worker will proxy it to the cache, even if the user is online (we can also fetch an updated version if the cached copy is out-of-date and store it for the next time the page gets loaded).

Demo will be available here at some point (it’s still on AppCache right now)

@cglong
Copy link

cglong commented Sep 8, 2018

It looks like, as of EdgeHTML 17.17063, Service Workers are enabled by default 😄

It'd be good to support this, as Service Workers are a requirement for submission to the Microsoft Store.

@j-f1
Copy link
Contributor Author

j-f1 commented Sep 8, 2018

Updated. Thanks!

@jmerle
Copy link
Contributor

jmerle commented Feb 15, 2019

Since Chrome 68 the "Add to homescreen button" is no longer available for manual use on Android. Instead, websites can trigger an "Add to homescreen" dialog if the website meets certain criteria. One of these criteria is registering a service worker with a fetch event handler, so that's another vote towards this issue.

@ryanburnette
Copy link

Thumbs up to converting devdocs from appcache to serviceworkers.

@eloyesp
Copy link

eloyesp commented May 21, 2019

I would vote against that, because I like this project and Service Workers might be insecure so are disabled by many people (me included).

@ryanburnette
Copy link

The method the site currently uses to provide offline functionality is on its way to being deprecated. If there isn't a move to service workers we'll probably lose offline functionality.

It won't be terribly hard to do anyway. Once the site is cached for offline use, the rest of the data is installed into localStorage.

@abraham
Copy link

abraham commented May 21, 2019

@eloyesp you mention "insecure" except the linked question is regarding privacy. Privacy and security are different (although related).

Regarding the privacy concerns of service workers, there is negligible risk. Service workers get woken up to handle two types of events: fetch and push.

  • fetch means that an HTTP request is already being made and can send data to a server without a SW existing.
  • push means that the server is sending a push notification that the user had to have opted into and the app has to show browser notification so the user knows the app is active. Being opt-in the privacy risk is minimal.

SWs don't fundamentally change the security and privacy models of the web. Origin restrictions, CORS, etc are all still in effect.

@jwkicklighter
Copy link

Just wanted to chime in that I'd personally like this so that the site can be installed as a standalone PWA on desktop environments as well.

@jmerle
Copy link
Contributor

jmerle commented Jun 16, 2019

I will start working on this next week, although it might take a while to complete because it's quite a big change. I will comment on this issue when I make significant progress and/or when I get a working demo with service workers online.

@jmerle
Copy link
Contributor

jmerle commented Jul 10, 2019

Time for an update. I have successfully replaced the App Cache with a Service Worker in jmerle/devdocs#service-worker. There is a live demo running at sw.devdocs.jmerle.dev.

This change to a Service Worker also means that DevDocs will be an installable PWA.

I have already tested the changes on the following browsers:

  • Chrome 75 on Ubuntu 18.04
  • Firefox 67 on Ubuntu 18.04
  • Opera 62 on Ubuntu 18.04
  • Chrome 75 on Android 9
  • Firefox 67 on Android 9

Because I do not have access to any Windows or Apple machines at the moment and don't want to have such a change deployed without knowing it works on all our supported platforms, it would be really nice if some people can test the changes on a recent version of Edge on Windows, Safari on macOS and Safari on iOS.

To help test the changes, do the following:

  1. Go to sw.devdocs.jmerle.dev.
  2. Wait a few seconds for all assets to be cached and then go offline (either via the OS or via the browser's DevTools).
  3. Refresh the page.
  4. If everything goes well, DevDocs loads as usual (even though you're offline).
  5. (skip on mobile) Resize the sidebar and refresh again.
  6. (skip on mobile) If everything goes well, the resizing of the sidebar is persistent even when offline (something that isn't the case with the current App Cache approach).
  7. Comment on this issue with the browser version, the OS and whether everything went well or not.

cc @cglong @j-f1

@j-f1
Copy link
Contributor Author

j-f1 commented Jul 10, 2019

Works on Safari on iOS 12.3.1 🎉

@j-f1
Copy link
Contributor Author

j-f1 commented Jul 10, 2019

And on Safari 12.1 on macOS 10.14.4.

@jmerle
Copy link
Contributor

jmerle commented Jul 10, 2019

Sweet, thanks! If someone can confirm it works on Edge I'll open a PR.

@cglong
Copy link

cglong commented Jul 10, 2019

@jmerle I can verify with Edge in an hour or two 🙂

@cglong
Copy link

cglong commented Jul 11, 2019

@jmerle, just tried it out using EdgeHTML 18.18362 on Windows 10 Version 1903. Looks great; thank you for taking the time to implement this! A few notes:

  • Refreshing the page while offline successfully loaded the page
  • Resizing the sidebar and refreshing was persistent
  • Attempting to navigate to any page within DevDocs while offline rendered the below error, even if I had previously visited the page

I could definitely have been doing something wrong (or perhaps this was intentional at this time), so please let me know if there's anything else I can do to help debug :)

image

@jwkicklighter
Copy link

@cglong I haven't looked at the inner-workings, but did you try marking some docs as available for offline in the settings, rather than just visiting them once?

@jmerle
Copy link
Contributor

jmerle commented Jul 11, 2019

@cglong thanks for testing it on Edge! The error you see can indeed be caused by not having downloaded the documentation for offline usage, although our current App Cache version of DevDocs does seem to support loading documentation entries without downloading them for offline usage when you have visited the entry before. While implementing something similar with service workers is possible, I'll leave that open for a future PR. I have updated the error message slightly to tell users to install documentations before going offline and have created a PR at #1022:

@cglong
Copy link

cglong commented Jul 11, 2019

@jwkicklighter @jmerle Oh duh, I forgot I had to do this 😅 Sorry! I just tried requesting the docs be installed and verified everything works as expected in Edge 😎

@jwkicklighter
Copy link

@jmerle thanks for getting this done so quickly, it was the biggest feature I've wanted to see since I started using devdocs!

@jmerle
Copy link
Contributor

jmerle commented Jul 19, 2019

The service worker changes are now live on devdocs.io 🎉

@trysten
Copy link
Contributor

trysten commented Dec 18, 2020

Can this issue be closed, since Service Worker is implemented?

@ojeytonwilliams
Copy link
Contributor

Yes, this can be closed. Thanks, @trysten.

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

No branches or pull requests

9 participants