I am setting a precache controller following the documentation. It seems to work fine, only for the cleanup part.
// Precache items
const precacheManifest =
[
{url: offlinePage, revision: '1.0.2'},
{url: HomePage, revision: '1.0.2'},
{url: './image/placeholder.png', revision: '1'},
{url: './manifest.json', revision: '1.0.1'},
];
const precacheController = new workbox.precaching.PrecacheController(precacheName);
precacheController.addToCacheList(precacheManifest);
Install event works fine and inserts into cache on install.
/**
* Install [Event]
*/
self.addEventListener('install', event => {
console.log('install event.');
event.waitUntil(precacheController.install());
});
The issue is with activate event it returns an error in the console:
Uncaught TypeError: precacheController.cleanup is not a function.
/**
* Activate [Event]
*/
self.addEventListener('activate', event => {
console.log('activate event.');
event.waitUntil(precacheController.cleanup());
});
What is wrong with my implementation? I am using Workbox 3.6.1
It turned out precacheController.cleanup() is the wrong method to call.
The correct one form the last documentation:
/**
* Activate [Event]
*/
self.addEventListener('activate', event => {
console.log('activate event.');
event.waitUntil(precacheController.activate());
});