workbox-precaching

The precaching library intelligently caches and updates files during the install step of your service worker.

When given a list of URL's to precache, this module will go through each URL and check if the URL is already cached and, if it is, compare the hash to see if revision hash has changed.

If the revision is old or the entry isn't cached, this library will make a request for the asset and cache it, ensuring the the browsers HTTP cache is skipped by using Request.cache = 'reload' or adding a cache busting search parameter to the request.

Example
importScripts('/<Path to Module>/build/workbox-precaching.min.js');

const revCacheManager = new workbox.precaching.RevisionedCacheManager();
revCacheManager.addToCacheList({
  revisionedFiles: [
    '/styles/main.1234.css',
    {
      url: '/',
      revision: '1234'
    }
  ],
});

self.addEventListener('install', (event) => {
  event.waitUntil(
    revCacheManager.install()
  );
});

self.addEventListener('activate', (event) => {
  event.waitUntil(
    revCacheManager.cleanup()
  );
});

Classes

BaseCacheManager
RevisionedCacheManager