siimonevans / notes

Offline-first notepad PWA

Home Page:https://sii.im/playground/notes/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

General question about offline availability.

mark-buhagiar opened this issue · comments

Hi, jumping straight to the point.

I understand that ServiceWorkers aren't yet supported on iOS, and as such, not available for chrome on iOS either. However, when testing on an iPhone, Notes works when I turn on airplane mode, meaning that it does in fact work offline. How is this possible? I understand that you're using Jake Archibald's cache-polyfill, but with the way your code is written, this shouldn't even be included (since the inclusion only happens if service workers are available on the navigator).

Therefore, in order to try and better understand this black magic, I decided to clone your repo and upload a version to surge.sh here. However, much to my surprise, this did not work offline!

Could you be kind enough to give me a very quick explanation of how Notes works offline without ServiceWorkers? Thanks.

Notes works offline without ServiceWorkers

I'm assuming you're suggesting you can interact and store notes with the app while offline, but refreshing the page results in an offline error. If you're managing to refresh the app while offline on iOS, then that really is magic.

The app is built with service worker, as you say. However, service worker is only being used to cache the application itself, not the application data - the individual notes are actually being stored with the help of the browser's local storage which is very widely supported.

In fact, service worker isn't intended to be used to directly store data in the way I believe you're thinking of. Instead, you should use a database/storage of some kind which in turn is cached as necessary by service worker - directly saving data to service worker via the DOM isn't possible. In this example, using local storage prevented the need to worry about caching this data since it's an offline storage solution in itself.

As for your cloned copy of the app not working as expected when hosted elsewhere, I'm afraid I don't know. However, I quickly tested it myself and it behaved in the same way as my version.

Hope that helps!

I'm assuming you're suggesting you can interact and store notes with the app while offline, but refreshing the page results in an offline error. If you're managing to refresh the app while offline on iOS, then that really is magic.

Yep, note the screenshot below. Airplane mode is on and the site is working. I tried refreshing, opening in a new tab, killing the browser from memory and reopening, and it still works. I guess it is black magic then.

jfhh3uz

The rest I had understood and agree with.

Thanks again.

Impressive! I'm afraid I can only assume it's a bug of some kind - I can't replicate the issue on my device.