npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dreamworld/workbox-installer

v1.6.0

Published

A helper library to install a Service Worker generated using [Workbox][workbox] into/for PWA(Progressive Web App).

Downloads

424

Readme

Workbox Installer

A helper library to install a Service Worker generated using Workbox into/for PWA(Progressive Web App).

Behaviours

  • When the app is accessed for the very first time, that tab starts using the service-worker as soon as the service-worker is installed. So, for example, when a page is switched, a new fragment is loaded from the service-worker cache.
  • When an app is updated from one of the browser tabs, other tabs are automatically reloaded to ensure that all the tabs are using the latest version of the app.
  • Asks for the confirmation only when the new service worker is installed & ready to use (when all the updated and new resources are already pre-cached).

Getting Strated

  1. Configure your PWA build-script to build service-worker.js using workbox, and set clientsClaim=true & skipWaiting=false options. You would like to configure other options for your PWA as shown in this demo. Feel free to chose your preferred way of the build.
  2. Add this library to your dependency. npm install --save workbox-installer
  3. Install Service Worker.
import { default as installWorkbox } from '@dreamworld/workbox-installer';

installWorkbox('/service-worker.js');

User won't see any notification about the new version available. But, This will ensure that the user will get the latest version of the App (service-worker) installed/updated on the page reload (or on the next visit).

Though, It’s side effect is that, when the app is opened in the 2nd browser tab, it is updated automatically; unwantedly.

New Version Notification

If you want to show your users a notification when a new version is available. And want to update the App only after user confirms update. Then register a confirmUpdate handler function too.

installWorkbox({
  url: '/service-worker.js', 
  confirmUpdate: () => {
    //Create a Promise & return it.
    //Show notification to your user
    //When user confirms, resolve the promise.
  }
});

Update Checker

In the above methods, whether a new version of the service-worker is available or not, is checked only on the page reload. But, if you want to customize the update checking process, e.g. Listen on the firebase realtime database changes and show a notification to the user as soon as the new version is released. Then, you need to provide UpdateChecker.

Example usage:

installWorkbox({
  url: '/service-worker.js', 
  confirmUpdate: (updates) => {
    //Here, `updates` is the updates notified by the `UpdateChecker` you provided.
    //Create a Promise & return it.
    //Show notification to your user
    //When user confirms, resolve the promise.
  },
  updateChecker: yourUpdateChecker
});

Following implementations of the UpdateChecker are available, check them if you can use one of them. Otherwise, you can always provide your custom implementation as per your requirement.