1
0
Fork 0
mirror of https://github.com/dilllxd/gitfolio.git synced 2024-08-14 22:28:09 +00:00
gitfolio/assets/service-worker.js

43 lines
1 KiB
JavaScript
Raw Normal View History

2019-12-11 17:10:27 +00:00
importScripts(
2020-01-12 09:38:32 +00:00
"https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js"
2019-12-11 17:10:27 +00:00
);
2019-12-11 17:10:27 +00:00
if (workbox) {
2020-01-12 09:38:32 +00:00
workbox.setConfig({
debug: false
});
2020-01-12 09:38:32 +00:00
const defaultStrategy = workbox.strategies.networkFirst({
cacheName: "fallback",
plugins: [
new workbox.expiration.Plugin({
maxEntries: 128,
maxAgeSeconds: 7 * 24 * 60 * 60, // 1 week
purgeOnQuotaError: true // Opt-in to automatic cleanup
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200] // For opague requests
})
]
});
workbox.routing.setDefaultHandler(args => {
if (args.event.request.method === "GET") {
return defaultStrategy.handle(args); // Use default strategy
}
2020-01-12 09:38:32 +00:00
return null;
});
2020-01-12 09:38:32 +00:00
workbox.routing.registerRoute(
new RegExp(/.*\.(?:js|css)/g),
workbox.strategies.networkFirst()
);
2020-01-11 16:48:56 +00:00
2020-01-12 09:38:32 +00:00
workbox.routing.registerRoute(
new RegExp(/.*\.(?:png|jpg|jpeg|svg|gif|webp)/g),
workbox.strategies.cacheFirst()
);
2019-12-11 17:10:27 +00:00
} else {
2020-01-12 09:38:32 +00:00
console.log("No workbox on this browser 😬");
2019-12-11 17:10:27 +00:00
}