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