a-painter icon indicating copy to clipboard operation
a-painter copied to clipboard

Introduce Service Worker to improve speed (and help with unreliable, offline connections)

Open cvan opened this issue 7 years ago • 7 comments

A Service Worker would be good to introduce to help the load times. Even on subsequent loads, the time to first byte (even for the 304 requests with E-Tag headers) can add up.

I'd recommend using https://github.com/GoogleChrome/sw-toolbox or a snippet from https://serviceworke.rs/. I have several handy but I'd recommend starting with sw-toolbox.

Cache the common assets first. And, we can look to possibly storing the responses to the Uploadcare requests using the Cache API (if the files are big, IndexedDB could be used as a last resort).

cvan avatar Sep 21 '16 09:09 cvan

Also could be useful: https://github.com/TalAter/UpUp

cvan avatar Sep 21 '16 10:09 cvan

Since users can also save their painting in a local file, the offline option is interesting!

feiss avatar Sep 21 '16 12:09 feiss

Example: load a drawing URL once, close the tab, and load it again. On my connection, this drawing takes over 6 seconds to load on subsequent refreshes (even with all the 304 responses).

The drawing file clocks in at 568.303 KB, which isn't that large.

But, it's the whole request/response lifecycle that is eating up the time (even if the responses are already cached by the browser, which they are).

A simple Service Worker will obliterate these network bottlenecks. It's some low-hanging fruit to get some great improved perf.

I'd love to tackle this next week.

cvan avatar Sep 25 '16 02:09 cvan

@cvan I'v never worked with Service Worker before, do you mind giving some advices on how to deal with it, or start some wip PR?

fernandojsg avatar Oct 04 '16 00:10 fernandojsg

Yep, working on it for Puzzle Rain, so expect a PR for several repos soon.

cvan avatar Oct 04 '16 01:10 cvan

Cool! :)

fernandojsg avatar Oct 04 '16 07:10 fernandojsg

FYI: I made a tool for handling a Service Worker that is versioned based on a hash of static assets in a directory:

https://github.com/cvan/sherpy https://gist.github.com/cvan/b0b373442a69b298fc05d4a8a8001d5a

Might be useful out of the box, though you may have to tweak things slightly - YMMV.

cvan avatar Oct 28 '16 12:10 cvan