From beb2d1901982e34d2356ec6cdb34febee2e1a994 Mon Sep 17 00:00:00 2001 From: Andrey Kondratev <81143241+cockroach-eater@users.noreply.github.com> Date: Mon, 10 Nov 2025 16:27:35 +0500 Subject: [PATCH] version fix --- public/index.html | 6 +++--- src/server.ts | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/public/index.html b/public/index.html index 98c8abe..7bfdb42 100644 --- a/public/index.html +++ b/public/index.html @@ -65,8 +65,8 @@ - - + + @@ -203,6 +203,6 @@ - + diff --git a/src/server.ts b/src/server.ts index cb5dfa7..46ce286 100644 --- a/src/server.ts +++ b/src/server.ts @@ -44,7 +44,7 @@ app.use((req: Request, res: Response, next) => { // Optimized caching strategy app.use(express.static('public', { - maxAge: '365d', // Cache static assets for 1 year by default + maxAge: 0, // Don't cache by default, set specific headers below etag: true, lastModified: true, setHeaders: (res: Response, filePath: string) => { @@ -52,13 +52,21 @@ app.use(express.static('public', { if (filePath.match(/\.(jpg|jpeg|png|gif|ico|woff|woff2|ttf|eot|svg)$/)) { res.set('Cache-Control', 'public, max-age=31536000, immutable'); } - // Cache CSS and JS with version string for 1 year + // Cache CSS and JS with version string for 1 year (they have ?v= in URL) else if (filePath.match(/\.(css|js)$/)) { - res.set('Cache-Control', 'public, max-age=31536000, immutable'); // 1 year + res.set('Cache-Control', 'public, max-age=31536000, immutable'); } - // HTML files - short cache with revalidation + // HTML files - NO CACHE else if (filePath.match(/\.html$/)) { - res.set('Cache-Control', 'public, max-age=0, must-revalidate'); + res.set('Cache-Control', 'no-cache, no-store, must-revalidate'); + res.set('Pragma', 'no-cache'); + res.set('Expires', '0'); + } + // JSON files (version.json) - NO CACHE + else if (filePath.match(/\.json$/)) { + res.set('Cache-Control', 'no-cache, no-store, must-revalidate'); + res.set('Pragma', 'no-cache'); + res.set('Expires', '0'); } } })); @@ -99,8 +107,8 @@ app.get('/', (req: Request, res: Response) => { // Read HTML and inject version try { let html = fs.readFileSync(indexPath, 'utf8'); - // Replace version placeholders with actual version - html = html.replace(/\?v=\d+/g, `?v=${appVersion}`); + // Replace all version placeholders with actual version + html = html.replace(/\?v=(VERSION|\d+)/g, `?v=${appVersion}`); res.send(html); } catch (error) { logger.error('Error serving HTML:', error);