mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-18 12:11:52 +03:00
ee360403fd
- Not 100% offline yet, very minimal caching - Fix logo a little
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
|
import { ExpirationPlugin } from 'workbox-expiration';
|
|
import { RegExpRoute, registerRoute, Route } from 'workbox-routing';
|
|
import { CacheFirst, StaleWhileRevalidate } from 'workbox-strategies';
|
|
|
|
const imageRoute = new Route(
|
|
({ request, sameOrigin }) => {
|
|
return !sameOrigin && request.destination === 'image';
|
|
},
|
|
new CacheFirst({
|
|
cacheName: 'remote-images',
|
|
plugins: [
|
|
new ExpirationPlugin({
|
|
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
purgeOnQuotaError: true,
|
|
}),
|
|
new CacheableResponsePlugin({
|
|
statuses: [0, 200],
|
|
}),
|
|
],
|
|
}),
|
|
);
|
|
registerRoute(imageRoute);
|
|
|
|
// Cache /instance because masto.js has to keep calling it while initializing
|
|
const apiExtendedRoute = new RegExpRoute(
|
|
/^https?:\/\/[^\/]+\/api\/v\d+\/instance/,
|
|
new StaleWhileRevalidate({
|
|
cacheName: 'api-extended',
|
|
plugins: [
|
|
new ExpirationPlugin({
|
|
maxAgeSeconds: 24 * 60 * 60, // 1 day
|
|
}),
|
|
new CacheableResponsePlugin({
|
|
statuses: [0, 200],
|
|
}),
|
|
],
|
|
}),
|
|
);
|
|
registerRoute(apiExtendedRoute);
|
|
|
|
// Not caching API requests, doesn't seem to be necessary fo now
|
|
//
|
|
// const apiRoute = new RegExpRoute(
|
|
// /^https?:\/\/[^\/]+\/api\//,
|
|
// new StaleWhileRevalidate({
|
|
// cacheName: 'api',
|
|
// plugins: [
|
|
// new ExpirationPlugin({
|
|
// maxAgeSeconds: 60, // 1 minute
|
|
// }),
|
|
// new CacheableResponsePlugin({
|
|
// statuses: [0, 200],
|
|
// }),
|
|
// ],
|
|
// }),
|
|
// );
|
|
// registerRoute(apiRoute);
|