mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-03 23:10:50 +03:00
Fixes for SW caching
This commit is contained in:
parent
efb42ca911
commit
f3345ad9f8
1 changed files with 8 additions and 3 deletions
11
public/sw.js
11
public/sw.js
|
@ -16,13 +16,17 @@ const assetsRoute = new Route(
|
||||||
({ request, sameOrigin }) => {
|
({ request, sameOrigin }) => {
|
||||||
const isAsset =
|
const isAsset =
|
||||||
request.destination === 'style' || request.destination === 'script';
|
request.destination === 'style' || request.destination === 'script';
|
||||||
const hasHash = /-[0-9a-f]{4,}\./i.test(request.url);
|
const hasHash = /-[0-9a-z-]{4,}\./i.test(request.url);
|
||||||
return sameOrigin && isAsset && hasHash;
|
return sameOrigin && isAsset && hasHash;
|
||||||
},
|
},
|
||||||
new NetworkFirst({
|
new NetworkFirst({
|
||||||
cacheName: 'assets',
|
cacheName: 'assets',
|
||||||
networkTimeoutSeconds: 5,
|
networkTimeoutSeconds: 5,
|
||||||
plugins: [
|
plugins: [
|
||||||
|
new ExpirationPlugin({
|
||||||
|
maxEntries: 30,
|
||||||
|
purgeOnQuotaError: true,
|
||||||
|
}),
|
||||||
new CacheableResponsePlugin({
|
new CacheableResponsePlugin({
|
||||||
statuses: [0, 200],
|
statuses: [0, 200],
|
||||||
}),
|
}),
|
||||||
|
@ -44,7 +48,7 @@ const imageRoute = new Route(
|
||||||
cacheName: 'remote-images',
|
cacheName: 'remote-images',
|
||||||
plugins: [
|
plugins: [
|
||||||
new ExpirationPlugin({
|
new ExpirationPlugin({
|
||||||
maxEntries: 50,
|
maxEntries: 30,
|
||||||
purgeOnQuotaError: true,
|
purgeOnQuotaError: true,
|
||||||
}),
|
}),
|
||||||
new CacheableResponsePlugin({
|
new CacheableResponsePlugin({
|
||||||
|
@ -86,7 +90,7 @@ const apiExtendedRoute = new RegExpRoute(
|
||||||
cacheName: 'api-extended',
|
cacheName: 'api-extended',
|
||||||
plugins: [
|
plugins: [
|
||||||
new ExpirationPlugin({
|
new ExpirationPlugin({
|
||||||
maxAgeSeconds: 24 * 60 * 60, // 1 day
|
maxAgeSeconds: 12 * 60 * 60, // 12 hours
|
||||||
purgeOnQuotaError: true,
|
purgeOnQuotaError: true,
|
||||||
}),
|
}),
|
||||||
new CacheableResponsePlugin({
|
new CacheableResponsePlugin({
|
||||||
|
@ -128,6 +132,7 @@ const apiRoute = new RegExpRoute(
|
||||||
networkTimeoutSeconds: 5,
|
networkTimeoutSeconds: 5,
|
||||||
plugins: [
|
plugins: [
|
||||||
new ExpirationPlugin({
|
new ExpirationPlugin({
|
||||||
|
maxEntries: 30,
|
||||||
maxAgeSeconds: 5 * 60, // 5 minutes
|
maxAgeSeconds: 5 * 60, // 5 minutes
|
||||||
purgeOnQuotaError: true,
|
purgeOnQuotaError: true,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Reference in a new issue