perf: implement caching of static files
This commit is contained in:
parent
55c0eba6e4
commit
170fbabe5e
6
app.js
6
app.js
@ -38,7 +38,11 @@ app.use(
|
|||||||
app.set('view engine', 'pug'); // setting pug as a view engine
|
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.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
|
if (process.env.NODE_ENV === 'development') app.use(morgan('dev')); // for logging requests
|
||||||
// app.use(express.json({ limit: '3mb' })); // for parsing json
|
// app.use(express.json({ limit: '3mb' })); // for parsing json
|
||||||
|
@ -6,3 +6,5 @@ URL=http://localhost:3000
|
|||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
# change image quality
|
# change image quality
|
||||||
IMAGE_QUALITY=500
|
IMAGE_QUALITY=500
|
||||||
|
# cache duration for static assets(eg: '2.5 days', 3600, 2m)
|
||||||
|
CACHE_PERIOD=1h
|
Loading…
x
Reference in New Issue
Block a user