Adding Service worker to Jekyll Site
I finally added the service worker for my Jekyll site madhur.co.in.
For introduction, Service workers enable rich offline experiences, periodic background syncs and push notifications.
For start, I have just implemented offline caching of JS/CSS/HTML files so that the site can be browsed even when offline.
Here is the simplest definition of a service worker which generates the Url of pages so that they can be cached
The generated file can be seen at http://www.madhur.co.in/serviceWorker.js
In current implementation, the service worker will always return the response from the cache if one exists. However, there are lot of strategies which can be implemented for example:
- Cache Only
- Network only
- Cache First
- Network First
These and many other such patterns are documented in offline cookbook
These patterns can be easy implemented using sw-toolbox