sw: prevent caching map requests
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/474/head
parent
d0c10b5333
commit
9b2af90546
|
@ -1,24 +1,30 @@
|
|||
import { precacheAndRoute } from 'workbox-precaching';
|
||||
import { NetworkFirst, CacheFirst, NetworkOnly } from 'workbox-strategies';
|
||||
import { registerRoute } from 'workbox-routing';
|
||||
import { ExpirationPlugin } from 'workbox-expiration';
|
||||
import { precacheAndRoute } from "workbox-precaching";
|
||||
import { NetworkFirst, CacheFirst, NetworkOnly } from "workbox-strategies";
|
||||
import { registerRoute } from "workbox-routing";
|
||||
import { ExpirationPlugin } from "workbox-expiration";
|
||||
|
||||
precacheAndRoute(self.__WB_MANIFEST);
|
||||
|
||||
registerRoute(/^.*\/apps\/memories\/api\/video\/transcode\/.*/, new NetworkOnly());
|
||||
registerRoute(
|
||||
/^.*\/apps\/memories\/api\/video\/transcode\/.*/,
|
||||
new NetworkOnly()
|
||||
);
|
||||
registerRoute(/^.*\/apps\/memories\/api\/image\/jpeg\/.*/, new NetworkOnly());
|
||||
registerRoute(/^.*\/apps\/memories\/api\/image\/preview\/.*/, new NetworkOnly());
|
||||
registerRoute(
|
||||
/^.*\/apps\/memories\/api\/image\/preview\/.*/,
|
||||
new NetworkOnly()
|
||||
);
|
||||
registerRoute(/^.*\/remote.php\/.*/, new NetworkOnly());
|
||||
registerRoute(/^.*\/apps\/files\/ajax\/download.php?.*/, new NetworkOnly());
|
||||
|
||||
const imageCache = new CacheFirst({
|
||||
cacheName: 'images',
|
||||
plugins: [
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 3600 * 24 * 7, // days
|
||||
maxEntries: 20000, // 20k images
|
||||
}),
|
||||
],
|
||||
cacheName: "images",
|
||||
plugins: [
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 3600 * 24 * 7, // days
|
||||
maxEntries: 20000, // 20k images
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
registerRoute(/^.*\/apps\/memories\/api\/video\/livephoto\/.*/, imageCache);
|
||||
|
@ -27,18 +33,22 @@ registerRoute(/^.*\/apps\/memories\/api\/tags\/preview\/.*/, imageCache);
|
|||
|
||||
registerRoute(/^.*\/apps\/memories\/api\/.*/, new NetworkOnly());
|
||||
|
||||
registerRoute(/^.*\/.*$/, new NetworkFirst({
|
||||
cacheName: 'pages',
|
||||
// Cache pages for same-origin requests only
|
||||
registerRoute(
|
||||
({ url }) => url.origin === self.location.origin,
|
||||
new NetworkFirst({
|
||||
cacheName: "pages",
|
||||
plugins: [
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 3600 * 24 * 7, // days
|
||||
maxEntries: 2000, // assets
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 3600 * 24 * 7, // days
|
||||
maxEntries: 2000, // assets
|
||||
}),
|
||||
],
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
// Take control of all pages under this SW's scope immediately,
|
||||
// instead of waiting for reload/navigation.
|
||||
event.waitUntil(self.clients.claim());
|
||||
self.addEventListener("activate", (event) => {
|
||||
// Take control of all pages under this SW's scope immediately,
|
||||
// instead of waiting for reload/navigation.
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue