Skip to content

doc: make docs available offline w/ServiceWorker

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

This is work in progress that I'm putting out here for public scrutiny.

I've been wanting to get my feet wet with ServiceWorkers for a while, so here's my first pet project. Since I've been bother by docs not being available on spotty connection while commuting or where there is no connection at all, I decided our docs would be nice to have available at all times.

How it works:

  1. ServiceWorker is registered immediately when visiting any doc page
  2. When visitor clicks the "Make available offline" link
  3. JavaScript finds all the relevant doc pages URLs, fetches the content and puts it into the ServiceWorker cache

To avoid caching docs too eagerly in step 2, I've put in a small check that ensure the docs currently displayed are for an exact version, not latest-v6.x or similar.

At the moment Firefox, Opera and Crome has ServiceWorker support, fingers crossed more will get support in the not too distant future: http://caniuse.com/#feat=serviceworkers

Got lots of inspiration from this cookbook: https://jakearchibald.com/2014/offline-cookbook/#on-background-sync

screen shot 2017-04-13 at 12 59 03 screen shot 2017-04-13 at 12 58 46

Any thoughts?

/cc @nodejs/documentation

Merge request reports

Loading