perf: implement caching of static files

This commit is contained in:
zyachel 2022-06-05 21:22:38 +05:30
parent 55c0eba6e4
commit 170fbabe5e
2 changed files with 8 additions and 2 deletions

6
app.js
View File

@ -38,7 +38,11 @@ app.use(
app.set('view engine', 'pug'); // setting pug as a view engine
app.set('views', path.join(__dirname, 'views/pug')); // directory from where html template will be sourced
app.use(express.static(path.join(__dirname, 'public'))); // directory from where files like css, images, fonts, will be sourced
app.use(
express.static(path.join(__dirname, 'public'), {
maxAge: process.env.CACHE_PERIOD || '1h',
})
); // directory from where files like css, images, fonts, will be sourced
if (process.env.NODE_ENV === 'development') app.use(morgan('dev')); // for logging requests
// app.use(express.json({ limit: '3mb' })); // for parsing json

View File

@ -6,3 +6,5 @@ URL=http://localhost:3000
NODE_ENV=production
# change image quality
IMAGE_QUALITY=500
# cache duration for static assets(eg: '2.5 days', 3600, 2m)
CACHE_PERIOD=1h