Improve platform performance and user experience with optimizations
This commit enhances performance by optimizing video card previews, implementing memoization for categories, debouncing search queries, and enabling compression and caching strategies on the server. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 890577b1-c154-40a4-a177-a0c6d55320c3 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/890577b1-c154-40a4-a177-a0c6d55320c3/dCPgsyV
This commit is contained in:
+21
-2
@@ -1,4 +1,5 @@
|
||||
import express, { type Request, Response, NextFunction } from "express";
|
||||
import compression from "compression";
|
||||
import { registerRoutes } from "./routes";
|
||||
import { videoSyncService } from "./videoSync";
|
||||
import { setupVite, serveStatic, log } from "./vite";
|
||||
@@ -7,18 +8,36 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const app = express();
|
||||
|
||||
// Enable gzip compression for faster responses
|
||||
app.use(compression());
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
|
||||
// Prevent caching issues middleware
|
||||
// Performance and caching middleware
|
||||
app.use((req, res, next) => {
|
||||
// Set no-cache headers for HTML pages to prevent blank screen issues
|
||||
// Set no-cache headers only for HTML pages to prevent blank screen issues
|
||||
if (req.path === '/' || req.path.endsWith('.html') || !req.path.includes('.')) {
|
||||
res.set({
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0'
|
||||
});
|
||||
}
|
||||
// Cache static assets for better performance
|
||||
else if (req.path.includes('/assets/') || req.path.match(/\.(js|css|png|jpg|jpeg|gif|ico|svg)$/)) {
|
||||
res.set({
|
||||
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||
'ETag': `"${Date.now()}"` // Simple ETag
|
||||
});
|
||||
}
|
||||
// Cache API responses for 30 seconds
|
||||
else if (req.path.startsWith('/api/videos') && req.method === 'GET') {
|
||||
res.set({
|
||||
'Cache-Control': 'public, max-age=30',
|
||||
'ETag': `"videos-${Date.now()}"`
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user