jo-gross / Cocktail-Manager

The Cocktail Manager is an efficient tool for easily documenting and accessing cocktail recipes behind the bar. It also includes essentail bar management features like cost calculations and stats tools.
Other
10 stars 1 forks source link

feat: Added offline availability with service workers #405

Closed Resaki1 closed 3 months ago

Resaki1 commented 3 months ago

Closing issues:

Before you mark this PR as ready, please check the following points

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Describe your work, what changed

Added the next-pwa plugin, which auto generates a service worker based on a config. This service worker can cache HTTP requests, which allows the site to be responsive even with slow or no network connection (as long as the requested parts of the site have been cached).

Additionally, I had a bug where visiting the site to create a cocktail wasn't possible when I didn't have any cocktails in the database. Was a simple fix.

Affected sites (please check during review):

all

Further comments

Explanation of the runtime caching config:

  1. All requests regarding the queue are set to NetworkOnly. This means, they are never served from cache, as that would create bugs.
  2. All other GET requests are set to StaleWhileRevalidate. This means, the service worker will always first check the cache and serve the response from there, if available. At the same time, the service worker will check the network (if available). If the data received over the network is newer than from cache, the data will be updated on the client and in the cache. Cache is kept valid for 14 days.

Demo

Here is a video showing the functionality. First, some parts of the site are visited with normal network connection. These are automatically cached. Then, the network connection is turned off, and the cached parts of the site still work fine. Things like the queue or adding cocktails to the statistics obviously don't work while offline.

jg-semantic-release-bot[bot] commented 2 months ago

:tada: This PR is included in version 1.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: