Live data from Hacker News

Writing a Service Worker

hacklabo.com

11–20 of 60 posts

Re: Writing a Service Worker

#11
post #3

Best use case of this I guess, is some kind of flight mode for web apps. Before going in to metro or flight, you click a button, and for example HN caches front page for you.

Caching cross-origin resources is problematic because you can't check the response code: https://stackoverflow.com/q/35626269

Re: Writing a Service Worker

#12
post #9

>This is, unfortunately, a familiar scene for everyone, whether you are in Tokyo, Milan or New York. Damn it, if I'm going to have the song stuck in my head all day so should all of you! https://www.youtube.com/watch?v=P5mtclwloEQ

[deleted]

Re: Writing a Service Worker

#13
post #3

Best use case of this I guess, is some kind of flight mode for web apps. Before going in to metro or flight, you click a button, and for example HN caches front page for you.

More than that - service workers have background sync and stuff like that as well. Imagine a messaging app where you can read and write messages no matter what the connectivity state is, then have the phone sync when you come back online.

Re: Writing a Service Worker

#14
Ah this is really nice but still feels quite verbose (+the web standards are know for their bad documentation for end devs). A small library with good documentation making things easier could kill it, similarly to localstorage, cookies, etc.

Re: Writing a Service Worker

#17

Ah this is really nice but still feels quite verbose (+the web standards are know for their bad documentation for end devs). A small library with good documentation making things easier could kill it, similarly to localstorage, cookies, etc.

I highly recommend using Workbox: https://workboxjs.org/.

One of the more gnarly parts of ServiceWorker is having to clean up old caches during a version change. The workbox-build module generates revision hashes for your pre-cached assets and handles any cache clean ups for you.

Re: Writing a Service Worker

#18

Could this be used to optionally reduce bandwidth use? For instance, could someone use this before going into Airplane Mode, even though they are in the middle of a city, but do not want to use wireless data?

Yep - that's one of the great things about service workers, IMO. The caching is pretty guaranteed, unlike the standard mobile caching which empties out far more often than you expect.
Post reply on HN