fix(cachemanager): Adjust cache control headers and fix redundant code

This commit is contained in:
Philipp Kunz 2025-02-03 00:16:58 +01:00
parent 021c980a4f
commit 4598bd0e25
3 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## 2025-02-03 - 3.0.56 - fix(cachemanager)
Adjust cache control headers and fix redundant code
- Remove duplicate assetbroker URLs in the cache evaluation logic.
- Update cache control headers to improve caching behavior.
- Increase the timeout for fetch operations to improve compatibility.
## 2025-01-28 - 3.0.55 - fix(server)
Fix response content manipulation for HTML files with injectReload

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedserver',
version: '3.0.55',
version: '3.0.56',
description: 'A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.'
}

View File

@ -98,8 +98,6 @@ export class CacheManager {
!originalRequest.url.includes('/api/') &&
!originalRequest.url.includes('smartserve/reloadcheck'))) ||
originalRequest.url.includes('https://assetbroker.') ||
originalRequest.url.includes('https://assetbroker.') ||
originalRequest.url.includes('https://assetbroker.') ||
originalRequest.url.includes('https://unpkg.com') ||
originalRequest.url.includes('https://fonts.googleapis.com') ||
originalRequest.url.includes('https://fonts.gstatic.com')
@ -150,9 +148,11 @@ export class CacheManager {
headers.set(key, value);
}
});
headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');
// Prevent browser caching while allowing service worker caching
headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
headers.set('Pragma', 'no-cache');
headers.set('Expires', '0');
headers.set('Surrogate-Control', 'no-store');
await cache.put(matchRequest, new Response(responseToPutToCache.body, {
...responseToPutToCache,
headers
@ -215,7 +215,7 @@ export class CacheManager {
// lets get a new response for comparison
const clonedRequest = requestArg.clone();
const response = await plugins.smartpromise.timeoutWrap(fetch(clonedRequest), 1000);
const response = await plugins.smartpromise.timeoutWrap(fetch(clonedRequest), 5000); // Increased timeout for better mobile compatibility
if (response && response.status >= 200 && response.status < 300) {
await runtimeCache.delete(requestArg);
await runtimeCache.put(requestArg, response);