Skip to content

Commit 573d054

Browse files
committed
♻️(SW) change strategy html caching
We will use the network first strategy for the html files. This will allow us to always have the latest version of the html files.
1 parent 2035a25 commit 573d054

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to
99

1010
## [Unreleased]
1111

12+
## Changed
13+
14+
♻️(SW) change strategy html caching #460
15+
1216

1317
## [1.8.1] - 2024-11-27
1418

src/frontend/apps/impress/src/features/service-worker/service-worker.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ setCacheNameDetails({
4747
const getStrategy = (
4848
options?: NetworkFirstOptions | StrategyOptions,
4949
): NetworkFirst | CacheFirst => {
50-
return SW_DEV_URL.some((devDomain) =>
50+
const isDev = SW_DEV_URL.some((devDomain) =>
5151
self.location.origin.includes(devDomain),
52-
) || isApiUrl(self.location.href)
52+
);
53+
const isApi = isApiUrl(self.location.href);
54+
const isHTMLRequest = options?.cacheName?.includes('html');
55+
56+
return isDev || isApi || isHTMLRequest
5357
? new NetworkFirst(options)
5458
: new CacheFirst(options);
5559
};
@@ -77,7 +81,7 @@ self.addEventListener('activate', function (event) {
7781
}),
7882
);
7983
})
80-
.then(void self.clients.claim()),
84+
.then(() => self.clients.claim()),
8185
);
8286
});
8387

@@ -139,6 +143,18 @@ setCatchHandler(async ({ request, url, event }) => {
139143
}
140144
});
141145

146+
// HTML documents
147+
registerRoute(
148+
({ request }) => request.destination === 'document',
149+
new NetworkFirst({
150+
cacheName: getCacheNameVersion('html'),
151+
plugins: [
152+
new CacheableResponsePlugin({ statuses: [0, 200] }),
153+
new ExpirationPlugin({ maxAgeSeconds: 24 * 60 * 60 * DAYS_EXP }),
154+
],
155+
}),
156+
);
157+
142158
/**
143159
* External urls cache strategy
144160
*/

0 commit comments

Comments
 (0)