DEV Community

PWAs that download like apps πŸ—œοΈ

Sam Thorogood on June 12, 2019

This is a short post today. (By writing that, it'll make it true!) It's also more of a short developer log, rather than having a specific point 😌 ...
Collapse
 
jeffposnick profile image
Jeff Posnick

From eyeballing your code, that promise passed to the install event's waitUntil() seems like it might resolve too early (it's not waiting for the untar() callback), and also would resolve even if the cache.put() call rejected.

Generally, you'd want to make sure that the promise passed to an install event's waitUntil() only fulfills iff all of the content that needs to be cached was successfully saved, and rejects otherwise.

Rejecting that waitUntil() promise will cause the newly registered service worker to enter the redundant state. The next time the same service worker gets registered, the install process will then run againβ€”and hopefully everything will be properly cached during that subsequent attempt.

Collapse
 
samthor profile image
Sam Thorogood • Edited

The call to untar in this case is actually totally synchronous so all the callbacks arrive before the async handler resolves. I modified the library which did use a Web Worker... anyway, the callback is fairly misleading- I'll fix it up.

Collapse
 
jeffposnick profile image
Jeff Posnick

Gotcha about the callback. But the cache.put() part could definitely fail asynchronously, which is not uncommon if you're, for instance, out of storage quota for your origin.

Collapse
 
ben profile image
Ben Halpern

I have four versions of the DEV desktop PWA installed πŸ˜„

Collapse
 
stefandorresteijn profile image
Stefan Dorresteijn • Edited

Awesome! I'm doing something like this using precache manifests for a PWA game I'm developing at rdlr.netlify.com/ (only intended to be visited on mobile) - It's 100% available offline and even has a fun little install screen.

Collapse
 
athmangude profile image
Athman Gude

This is awesome πŸ‘πŸ‘πŸ‘