From c75320645681fefa5f4a08e3c7ec73224f154f3d Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Fri, 23 Jan 2026 22:42:04 +0000 Subject: [PATCH] feat(typedserver): add noCache option to disable client-side caching and set no-cache headers on responses --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/classes.typedserver.ts | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index ef788ef..2eae24c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-01-23 - 8.3.0 - feat(typedserver) +add noCache option to disable client-side caching and set no-cache headers on responses + +- Introduces an optional noCache?: boolean in the server options interface +- applyResponseHeaders now sets Cache-Control, Pragma, and Expires headers when noCache is true +- Existing CORS and security header behavior unchanged when noCache is not set or false + ## 2026-01-23 - 8.2.0 - feat(typedserver) serve bundled in-memory content with caching and reload injection diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index f3663cb..4becbfc 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@api.global/typedserver', - version: '8.2.0', + version: '8.3.0', description: 'A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.' } diff --git a/ts/classes.typedserver.ts b/ts/classes.typedserver.ts index 06f0358..d5fedbc 100644 --- a/ts/classes.typedserver.ts +++ b/ts/classes.typedserver.ts @@ -157,6 +157,12 @@ export interface IServerOptions { * Set to true for defaults (brotli + gzip), false to disable, or provide detailed config */ compression?: plugins.smartserve.ICompressionConfig | boolean; + + /** + * Disable all client-side caching by setting appropriate headers + * Useful for development or when content changes frequently + */ + noCache?: boolean; } export type THttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'ALL'; @@ -635,11 +641,18 @@ export class TypedServer { } /** - * Apply all configured headers (CORS, security) to a response + * Apply all configured headers (CORS, security, cache control) to a response */ private applyResponseHeaders(response: Response): Response { const headers = new Headers(response.headers); + // No-cache headers + if (this.options.noCache) { + headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'); + headers.set('Pragma', 'no-cache'); + headers.set('Expires', '0'); + } + // CORS headers if (this.options.cors) { headers.set('Access-Control-Allow-Origin', '*');