Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created July 18, 2017 23:39
Show Gist options
  • Save gauntface/14b1e44338e631a3916f954f2bb95dfa to your computer and use it in GitHub Desktop.
Save gauntface/14b1e44338e631a3916f954f2bb95dfa to your computer and use it in GitHub Desktop.
"workbox.js" Concept class for a loader.
class Workbox {
constructor(options) {
console.log('[WorkboxLoader.constructor]', options.packagesPath);
this._packagesPath = options.packagesPath;
// This is required
this.loadModule('workbox-core');
}
loadModule(moduleName) {
console.log('[Loader.load()] ', moduleName);
importScripts(`${this._packagesPath}/${moduleName}/build/umd.js`);
}
get precaching() {
if (google.workbox.precaching) {
return google.workbox.precaching.default;
}
this.loadModule('workbox-precaching');
return google.workbox.precaching.default;
}
get routing() {
if (google.workbox.routing) {
return google.workbox.routing.default;
}
this.loadModule('workbox-routing');
return google.workbox.routing.default;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment