Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Last active March 5, 2020 10:57
Show Gist options
  • Save muxueqz/b6e4df5c4af8cd1afe7b1a9909a5f38e to your computer and use it in GitHub Desktop.
Save muxueqz/b6e4df5c4af8cd1afe7b1a9909a5f38e to your computer and use it in GitHub Desktop.
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts(
"./precache-manifest.clear.js"
);
self.addEventListener('message', (event) => {
console.log("message event");
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
self.addEventListener('install', function(event) {
console.log("install event");
self.skipWaiting();
});
self.addEventListener("activate", function(e) {
self.registration.unregister()
.then(function() {
return self.clients.matchAll();
})
.then(function(clients) {
clients.forEach(client => client.navigate(client.url));
});
console.log("unregister");
});
workbox.core.clientsClaim();
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
* v7
workbox.routing.registerNavigationRoute("https://faucet-old.nervos.org/?__WB_REVISION__=1", {
*/
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("./index.html"), {
blacklist: [/^\/_/,/\/[^\/?]+\.[^\/]+$/],
});
/**
navigator.serviceWorker.getRegistrations().then(
function(registrations) {
for(let registration of registrations) {
registration.unregister();
}
});
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
return caches.delete(key);
}));
});
location.reload();
workbox.precaching.cleanupOutdatedCaches();
*/
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
return caches.delete(key);
}));
});
var response;
fetch('/index.html?v10').then(function(r) {
response = r
self.caches.open('index.html?__WB_REVISION__=eab71aaeb03cc06c62805352eca56eeb').then(
function (cache) {
console.log(response)
cache.put('index.html?__WB_REVISION__=eab71aaeb03cc06c62805352eca56eeb', response)
}
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment