diff --git a/app.js b/app.js index fa14571..d9e4cd0 100644 --- a/app.js +++ b/app.js @@ -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 diff --git a/config.env.template b/config.env.template index a4191bd..991e280 100644 --- a/config.env.template +++ b/config.env.template @@ -5,4 +5,6 @@ URL=http://localhost:3000 # enviorment NODE_ENV=production # change image quality -IMAGE_QUALITY=500 \ No newline at end of file +IMAGE_QUALITY=500 +# cache duration for static assets(eg: '2.5 days', 3600, 2m) +CACHE_PERIOD=1h \ No newline at end of file