1.0.10 • Published 3 months ago

@jswork/sw-runtime v1.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

sw-runtime

Service worker runtime for workbox.

version license size download

installation

npm install @jswork/sw-runtime

skipWaiting

// case1: skipWaiting true: will be update immediately
module.exports = {
  maximumFileSizeToCacheInBytes: 100 * 1024 * 1024,
  globDirectory: 'build/',
  globPatterns: ['**/*.{js,png,json,txt,css,map}'],
  globIgnores: ['*/fallback.js'],
  skipWaiting: true,
  clientsClaim: true,
  //...
};

// case2: skipWaiting false: will be update when you click sw-tips `reload` button
module.exports = {
  maximumFileSizeToCacheInBytes: 100 * 1024 * 1024,
  globDirectory: 'build/',
  globPatterns: ['**/*.{js,png,json,txt,css,map}'],
  globIgnores: ['*/fallback.js'],
  skipWaiting: false,
  clientsClaim: false,
  //...
};

usage

import SwRuntime from '@jswork/sw-runtime';

// App Did Mount, config sw
window.onload = function () {
  SwRuntime.install({
    autoUpdate: true,
    autoUpdateInterval: 5 * 1000,
    onAutoUpdate: function () {
      console.log('SW Event:', 'onAutoUpdate');
    },
    onUpdateReady: function ({ context }) {
      console.log('SW Event:', 'onUpdateReady');
      setTimeout(function () {
        console.log('SW Event:', 'do applyUpdate');
        // Need to reload page, or it will be pending.
        context.applyUpdate().then(()=>{
          window.location.reload();
        });
      }, 1000);
    },
  });
};

todos

  1. unpkg/jsdelivr cdn zero cache?(not ok)
  2. auto update interval(ok)

license

Code released under the MIT license.

1.0.10

3 months ago

1.0.9

3 months ago

1.0.8

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

1.0.2

4 months ago

1.0.1

4 months ago