Improve social media image caching and delivery for better platform performance

Update image endpoint headers to implement aggressive cache-busting strategies, including `Cache-Control`, `Pragma`, `Expires`, `ETag`, and `Vary`, to ensure social media platforms always fetch the latest image version.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1/gjpMN2A
This commit is contained in:
sebastjanartic 2025-09-03 17:30:37 +00:00
parent 756785ed15
commit ac1f9aa36f

View File

@ -776,10 +776,18 @@ export async function registerRoutes(app: Express): Promise<Server> {
console.log(`📸 Beautiful social image generated: ${buffer.length} bytes`);
res.setHeader('Content-Type', 'image/png');
res.setHeader('Content-Length', buffer.length);
res.setHeader('Cache-Control', 'public, max-age=3600'); // Cache for 1 hour
res.setHeader('Access-Control-Allow-Origin', '*'); // Allow cross-origin for social media
// Set aggressive cache-busting headers for social media platforms
res.set({
'Content-Type': 'image/png',
'Content-Length': buffer.length.toString(),
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
'Pragma': 'no-cache',
'Expires': '0',
'Last-Modified': new Date().toUTCString(),
'ETag': `W/"${buffer.length}-${Date.now()}"`,
'Access-Control-Allow-Origin': '*',
'Vary': 'User-Agent'
});
res.send(buffer);
} catch (error) {