100!
This commit is contained in:
@@ -43,21 +43,21 @@ app.use((req: Request, res: Response, next) => {
|
||||
|
||||
// Optimized caching strategy
|
||||
app.use(express.static('public', {
|
||||
maxAge: '1d', // Cache static assets for 1 day
|
||||
maxAge: '365d', // Cache static assets for 1 year by default
|
||||
etag: true,
|
||||
lastModified: true,
|
||||
setHeaders: (res: Response, filePath: string) => {
|
||||
// Cache images, fonts, etc. longer
|
||||
if (filePath.match(/\.(jpg|jpeg|png|gif|ico|woff|woff2|ttf|eot)$/)) {
|
||||
// Cache images, fonts, etc. with immutable flag
|
||||
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
|
||||
// Cache CSS and JS with version string for 1 year
|
||||
else if (filePath.match(/\.(css|js)$/)) {
|
||||
res.set('Cache-Control', 'public, max-age=86400'); // 1 day
|
||||
res.set('Cache-Control', 'public, max-age=31536000, immutable'); // 1 year
|
||||
}
|
||||
// HTML files - short cache
|
||||
// HTML files - short cache with revalidation
|
||||
else if (filePath.match(/\.html$/)) {
|
||||
res.set('Cache-Control', 'public, max-age=3600'); // 1 hour
|
||||
res.set('Cache-Control', 'public, max-age=0, must-revalidate');
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user